Skip to content

Commit d40a563

Browse files
author
Matt Way
authored
Merge pull request #1 from heypinch/chore/fix-hash-mem
Hash - changed to chunk size instead of reading entire file
2 parents 085db09 + ee6b4cb commit d40a563

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -876,11 +876,12 @@ static void hash(String path, String algorithm, Promise promise) {
876876
MessageDigest md = MessageDigest.getInstance(algorithms.get(algorithm));
877877

878878
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];
880881

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);
884885
}
885886

886887
StringBuilder hexString = new StringBuilder();

0 commit comments

Comments
 (0)