|
@@ -24,6 +24,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule;
|
24
|
24
|
|
25
|
25
|
import java.io.File;
|
26
|
26
|
import java.io.FileInputStream;
|
|
27
|
+import java.io.FileNotFoundException;
|
27
|
28
|
import java.io.FileOutputStream;
|
28
|
29
|
import java.io.IOException;
|
29
|
30
|
import java.io.InputStream;
|
|
@@ -536,6 +537,39 @@ public class RNFetchBlobFS {
|
536
|
537
|
callback.invoke(null, arg);
|
537
|
538
|
}
|
538
|
539
|
|
|
540
|
+ /**
|
|
541
|
+ * Create a file by slicing given file path
|
|
542
|
+ * @param src Source file path
|
|
543
|
+ * @param dest Destination of created file
|
|
544
|
+ * @param start Start byte offset in source file
|
|
545
|
+ * @param end End byte offset
|
|
546
|
+ * @param encode
|
|
547
|
+ * @param callback
|
|
548
|
+ */
|
|
549
|
+ public static void slice(String src, String dest, int start, int end, String encode, Callback callback) {
|
|
550
|
+ try {
|
|
551
|
+ long expected = end - start;
|
|
552
|
+ long now = 0;
|
|
553
|
+ FileInputStream in = new FileInputStream(new File(src));
|
|
554
|
+ FileOutputStream out = new FileOutputStream(new File(dest));
|
|
555
|
+ in.skip(start);
|
|
556
|
+ byte [] buffer = new byte[10240];
|
|
557
|
+ while(now < expected) {
|
|
558
|
+ long read = in.read(buffer, 0, 10240);
|
|
559
|
+ if(read <= 0) {
|
|
560
|
+ break;
|
|
561
|
+ }
|
|
562
|
+ now += read;
|
|
563
|
+ out.write(buffer, 0, (int) read);
|
|
564
|
+ }
|
|
565
|
+ in.close();
|
|
566
|
+ out.close();
|
|
567
|
+ callback.invoke(null, dest);
|
|
568
|
+ } catch (Exception e) {
|
|
569
|
+ e.printStackTrace();
|
|
570
|
+ }
|
|
571
|
+ }
|
|
572
|
+
|
539
|
573
|
static void lstat(String path, final Callback callback) {
|
540
|
574
|
path = normalizePath(path);
|
541
|
575
|
|