Skip to content

Commit

Permalink
Merge pull request #437 from heypinch/master
Browse files Browse the repository at this point in the history
Hash function allocates too much memory for large files
  • Loading branch information
Traviskn authored Sep 26, 2019
2 parents 86dc386 + d40a563 commit 9a43620
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,12 @@ static void hash(String path, String algorithm, Promise promise) {
MessageDigest md = MessageDigest.getInstance(algorithms.get(algorithm));

FileInputStream inputStream = new FileInputStream(path);
byte[] buffer = new byte[(int)file.length()];
int chunkSize = 4096 * 256; // 1Mb
byte[] buffer = new byte[chunkSize];

int read;
while ((read = inputStream.read(buffer)) != -1) {
md.update(buffer, 0, read);
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
md.update(buffer, 0, bytesRead);
}

StringBuilder hexString = new StringBuilder();
Expand Down

0 comments on commit 9a43620

Please sign in to comment.