Pārlūkot izejas kodu

Merge pull request #437 from heypinch/master

Hash function allocates too much memory for large files
Travis Nuttall 5 gadus atpakaļ
vecāks
revīzija
9a43620de3
No account linked to committer's email address

+ 5
- 4
android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java Parādīt failu

@@ -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();