浏览代码

Merge pull request #437 from heypinch/master

Hash function allocates too much memory for large files
Travis Nuttall 5 年前
父节点
当前提交
9a43620de3
没有帐户链接到提交者的电子邮件
共有 1 个文件被更改,包括 5 次插入4 次删除
  1. 5
    4
      android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

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

@@ -888,11 +888,12 @@ class RNFetchBlobFS {
888 888
             MessageDigest md = MessageDigest.getInstance(algorithms.get(algorithm));
889 889
 
890 890
             FileInputStream inputStream = new FileInputStream(path);
891
-            byte[] buffer = new byte[(int)file.length()];
891
+            int chunkSize = 4096 * 256; // 1Mb
892
+            byte[] buffer = new byte[chunkSize];
892 893
 
893
-            int read;
894
-            while ((read = inputStream.read(buffer)) != -1) {
895
-                md.update(buffer, 0, read);
894
+            int bytesRead;
895
+            while ((bytesRead = inputStream.read(buffer)) != -1) {
896
+                md.update(buffer, 0, bytesRead);
896 897
             }
897 898
 
898 899
             StringBuilder hexString = new StringBuilder();