-
Notifications
You must be signed in to change notification settings - Fork 468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide functionality for calculating MD5 hashes of files #48
Comments
If not, I think it would be nice to show this example in the README, so that people are more willing to copy-paste it into their projects. |
Hello @janko-m. This library was primally made to be used in browser like environments. While it works in node, using the native Having a method to read files and calculate the hash out of it would have to cater how to really read the files based on the environment: browser-like or node. Because of that, I don't think it makes much sense to have that built-in. I'm willing to improve the README to make it clear how to calculate the hash of a file in both browser and node environments. Could you make a PR to add examples of both environments? The current example is for a browser environment. Makes sense? |
Hey @satazor, thanks for a quick answer.
I was under the impression that this library was already considered "browser-only", because, as you said, for Node there is already the
My intention was simplifying only the browser example that's already there, as I only have experience with using spark-md5 in the browser. Great, I'll send the PR then 👍 |
The chunked-file-reader comes with the functionality of reading a file in chunks, so we can simplify the file example a lot by offloading this logic to that package. I think this will make it much more approachable for people wanting to reuse that code. The chunked-file-reader package uses `readAsArrayBuffer()`, and we cannot use it for tests that use `readAsBinaryString()`. Also, chunked-file-reader always uses `File.prototype.slice`, but I think that's ok now, since `blob.mozSlice()` is only needed for Firefox 12 and earlier, though I don't on which version did Safari start supporting `File.prototype.slice` (I tested that it works on Safari 11 which is the current latest version). Closes satazor#48
First of all, thanks a lot for creating this very useful library! 🙏
I recently needed to calculate an MD5 hash of a
File
object, and while I saw the section in the README showing how to do that, I really didn't like how much custom code it involves.I was wondering, could maybe this functionality be part of this library? In comparison, Ruby has a
Digest::MD5
class which supports calculating hash from a single string, incremental hashing in chunks, and calculating a hash from a file on disk.I took me quite a while to find a JavaScript library which simplifies reading a
File
object in chunks – chunked-file-reader – and it appears to work correctly (I get the same MD5 hash as with the snippet in the README here). So I came up with the following function:Since it took me a while to come up with this solution, I was wondering if it made sense to have that built into spark-md5.
The text was updated successfully, but these errors were encountered: