js-crc32 icon indicating copy to clipboard operation
js-crc32 copied to clipboard

Add bufrange to support reusing buffers

Open martin-knopf opened this issue 1 year ago • 0 comments

Hi!

I have recently used this library in the context of content-defined chunking, where I read a file into a buffer and calculate hashes of a sliding window. This produces as many hashes as there are bytes in the buffer. To get the next window, I used Buffer.subarray(), but this is pretty slow because it creates a new buffer. So, with this PR, I would like to propose CRC32.bufrange(buffer, start, end, [, seed]), which allows reusing the same buffer.

Unfortunately, I don’t understand your codebase well enough to know where this new function should go. For starters, I have only added it to crc32.js, but I would be happy to complete this PR with your help.

Best, Martin

martin-knopf avatar Sep 23 '24 09:09 martin-knopf