Browse Source

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

Hash - changed to chunk size instead of reading entire file
Matt Way 4 years ago
parent
commit
d40a5632d1
No account linked to committer's email address
1 changed files with 5 additions and 4 deletions
  1. 5
    4
      android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

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

876
             MessageDigest md = MessageDigest.getInstance(algorithms.get(algorithm));
876
             MessageDigest md = MessageDigest.getInstance(algorithms.get(algorithm));
877
 
877
 
878
             FileInputStream inputStream = new FileInputStream(path);
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
             StringBuilder hexString = new StringBuilder();
887
             StringBuilder hexString = new StringBuilder();