ronomon / crypto-async

Fast, reliable cipher, hash and hmac methods executed in Node's threadpool for multi-core throughput.
MIT License
174 stars 15 forks source link

How to use hash function to hash a file stream? #4

Closed matianfu closed 5 years ago

matianfu commented 7 years ago

It seems that in current version only a single buffer could be hashed. I want to use it to hash a file stream, like the built-in hash function in crypto module, where update can be called multiple times. Is it possible?

jorangreef commented 7 years ago

It's not yet possible. That would require keeping the C++ digest context alive across multiple update calls, a mutex to ensure that only one thread operates on the C++ digest context at a time, and a garbage collection mechanism to free the C++ digest context when the corresponding javascript instance is collected. It's more complicated than an async function call. I think it can be done but I can't look into it right away. Hopefully someone can help out with this.

jorangreef commented 5 years ago

@matianfu I'm going to close this, since streaming carries overhead and is one of our non-goals.

It would complicate @ronomon/crypto-async to add support for streaming. Perhaps one day, but I will re-open this then if that's fine with you.