瀏覽代碼

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 4 年之前
父節點
當前提交
b25baab96c
No account linked to committer's email address
共有 1 個文件被更改,包括 5 次插入3 次删除
  1. 5
    3
      android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

+ 5
- 3
android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java 查看文件

@@ -895,9 +895,11 @@ class RNFetchBlobFS {
895 895
             int chunkSize = 4096 * 256; // 1Mb
896 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 905
             StringBuilder hexString = new StringBuilder();