5

I'm trying to find a way to calculate the hash of large files in javascript without having to load the whole file in a FileReader. Is there a way to calculate the sha1 of a file by streaming it in javascript?

I'm looking at sha.js but I'm not sure how it could be done in JavaScript client side.

Nicolas Manzini
  • 8,379
  • 6
  • 63
  • 81

1 Answers1

2

I believe this has been answered here: Read file stream using javascript in web browser

The File API has a slice method that lets you read a file in parts.

https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice

For more information on how this can be done:

https://www.html5rocks.com/en/tutorials/file/dndfiles/

Google's implementation of SHA1 here:

https://github.com/google/closure-library/blob/master/closure/goog/crypt/sha1.js

squgeim
  • 2,321
  • 1
  • 14
  • 21