Skip to content

Commit b25baab

Browse files
authored
Merge pull request #423 from ankit-makwana/hash-fix
Fix #170 - RNFetchBlob fs hash with md5 param fails if the file size is 0(blank file)
2 parents ec79195 + fc7ae6c commit b25baab

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -895,9 +895,11 @@ static void hash(String path, String algorithm, Promise promise) {
895895
int chunkSize = 4096 * 256; // 1Mb
896896
byte[] buffer = new byte[chunkSize];
897897

898-
int bytesRead;
899-
while ((bytesRead = inputStream.read(buffer)) != -1) {
900-
md.update(buffer, 0, bytesRead);
898+
if(file.length() != 0) {
899+
int bytesRead;
900+
while ((bytesRead = inputStream.read(buffer)) != -1) {
901+
md.update(buffer, 0, bytesRead);
902+
}
901903
}
902904

903905
StringBuilder hexString = new StringBuilder();

0 commit comments

Comments
 (0)