瀏覽代碼

Merge pull request #1 from heypinch/chore/fix-hash-mem

Hash - changed to chunk size instead of reading entire file
Matt Way 5 年之前
父節點
當前提交
d40a5632d1
No account linked to committer's email address
共有 1 個檔案被更改,包括 5 行新增4 行删除
  1. 5
    4
      android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

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

@@ -876,11 +876,12 @@ class RNFetchBlobFS {
876 876
             MessageDigest md = MessageDigest.getInstance(algorithms.get(algorithm));
877 877
 
878 878
             FileInputStream inputStream = new FileInputStream(path);
879
-            byte[] buffer = new byte[(int)file.length()];
879
+            int chunkSize = 4096 * 256; // 1Mb
880
+            byte[] buffer = new byte[chunkSize];
880 881
 
881
-            int read;
882
-            while ((read = inputStream.read(buffer)) != -1) {
883
-                md.update(buffer, 0, read);
882
+            int bytesRead;
883
+            while ((bytesRead = inputStream.read(buffer)) != -1) {
884
+                md.update(buffer, 0, bytesRead);
884 885
             }
885 886
 
886 887
             StringBuilder hexString = new StringBuilder();