Sfoglia il codice sorgente

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

Hash - changed to chunk size instead of reading entire file
Matt Way 4 anni fa
parent
commit
d40a5632d1
No account linked to committer's email address

+ 5
- 4
android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java Vedi File

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