@@ -680,37 +680,36 @@ static void ls(String path, Promise promise) {
680
680
*/
681
681
static void slice (String path , String dest , int start , int end , String encode , Promise promise ) {
682
682
try {
683
- path = ReactNativeBlobUtilUtils .normalizePath (path );
684
683
dest = ReactNativeBlobUtilUtils .normalizePath (dest );
685
- File source = new File (path );
686
- if (source .isDirectory ()) {
687
- promise .reject ("EISDIR" , "Expecting a file but '" + path + "' is a directory" );
688
- return ;
684
+
685
+ if (!path .startsWith (ReactNativeBlobUtilConst .FILE_PREFIX_CONTENT )) {
686
+ File file = new File (ReactNativeBlobUtilUtils .normalizePath (path ));
687
+ if (file .isDirectory ()) {
688
+ promise .reject ("EISDIR" , "Expecting a file but '" + path + "' is a directory" );
689
+ return ;
690
+ }
689
691
}
690
- if (!source .exists ()) {
692
+
693
+ InputStream in = inputStreamFromPath (path );
694
+ if (in == null ) {
691
695
promise .reject ("ENOENT" , "No such file '" + path + "'" );
692
696
return ;
693
697
}
694
- int size = (int ) source .length ();
695
- int max = Math .min (size , end );
696
- int expected = max - start ;
697
- int now = 0 ;
698
- FileInputStream in = new FileInputStream (new File (path ));
699
698
FileOutputStream out = new FileOutputStream (new File (dest ));
700
699
int skipped = (int ) in .skip (start );
701
700
if (skipped != start ) {
702
- promise .reject ("EUNSPECIFIED" , "Skipped " + skipped + " instead of the specified " + start + " bytes, size is " + size );
701
+ promise .reject ("EUNSPECIFIED" , "Skipped " + skipped + " instead of the specified " + start + " bytes" );
703
702
return ;
704
703
}
705
704
byte [] buffer = new byte [10240 ];
706
- while (now < expected ) {
705
+ int remain = end - start ;
706
+ while (remain > 0 ) {
707
707
int read = in .read (buffer , 0 , 10240 );
708
- int remain = expected - now ;
709
708
if (read <= 0 ) {
710
709
break ;
711
710
}
712
711
out .write (buffer , 0 , (int ) Math .min (remain , read ));
713
- now + = read ;
712
+ remain - = read ;
714
713
}
715
714
in .close ();
716
715
out .flush ();
0 commit comments