@@ -846,31 +846,27 @@ static void hash(String path, String algorithm, Promise promise) {
846
846
return ;
847
847
}
848
848
849
- path = ReactNativeBlobUtilUtils .normalizePath (path );
850
-
851
- File file = new File (path );
852
-
853
- if (file .isDirectory ()) {
854
- promise .reject ("EISDIR" , "Expecting a file but '" + path + "' is a directory" );
855
- return ;
849
+ if (!path .startsWith (ReactNativeBlobUtilConst .FILE_PREFIX_CONTENT )) {
850
+ File file = new File (ReactNativeBlobUtilUtils .normalizePath (path ));
851
+ if (file .isDirectory ()) {
852
+ promise .reject ("EISDIR" , "Expecting a file but '" + path + "' is a directory" );
853
+ return ;
854
+ }
856
855
}
857
856
858
- if (!file .exists ()) {
857
+ MessageDigest md = MessageDigest .getInstance (algorithms .get (algorithm ));
858
+
859
+ InputStream inputStream = inputStreamFromPath (path );
860
+ if (inputStream == null ) {
859
861
promise .reject ("ENOENT" , "No such file '" + path + "'" );
860
862
return ;
861
863
}
862
-
863
- MessageDigest md = MessageDigest .getInstance (algorithms .get (algorithm ));
864
-
865
- FileInputStream inputStream = new FileInputStream (path );
866
864
int chunkSize = 4096 * 256 ; // 1Mb
867
865
byte [] buffer = new byte [chunkSize ];
868
866
869
- if (file .length () != 0 ) {
870
- int bytesRead ;
871
- while ((bytesRead = inputStream .read (buffer )) != -1 ) {
872
- md .update (buffer , 0 , bytesRead );
873
- }
867
+ int bytesRead ;
868
+ while ((bytesRead = inputStream .read (buffer )) != -1 ) {
869
+ md .update (buffer , 0 , bytesRead );
874
870
}
875
871
876
872
StringBuilder hexString = new StringBuilder ();
0 commit comments