Browse Source

Merge pull request #423 from ankit-makwana/hash-fix

Fix #170 - RNFetchBlob fs hash with md5 param fails if the file size is 0(blank file)
Travis Nuttall 5 years ago
parent
commit
b25baab96c
No account linked to committer's email address
1 changed files with 5 additions and 3 deletions
  1. 5
    3
      android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+ 5
- 3
android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java View File

895
             int chunkSize = 4096 * 256; // 1Mb
895
             int chunkSize = 4096 * 256; // 1Mb
896
             byte[] buffer = new byte[chunkSize];
896
             byte[] buffer = new byte[chunkSize];
897
 
897
 
898
-            int bytesRead;
899
-            while ((bytesRead = inputStream.read(buffer)) != -1) {
900
-                md.update(buffer, 0, bytesRead);
898
+            if(file.length() != 0) {
899
+                int bytesRead;
900
+                while ((bytesRead = inputStream.read(buffer)) != -1) {
901
+                    md.update(buffer, 0, bytesRead);
902
+                }
901
             }
903
             }
902
 
904
 
903
             StringBuilder hexString = new StringBuilder();
905
             StringBuilder hexString = new StringBuilder();