andykaisA
Denoβ€’2y agoβ€’
2 replies
andykais

recommended way to get file checksum

Hi, I am creating an application that needs to get checksums for files. The code currently looks like this:
import * as node_crypto from 'node:crypto'

  async function get_checksum() {
    const hash = node_crypto.createHash('sha256')
    using file = await Deno.open(this.#filepath)
    for await (const chunk of file.readable) {
      hash.update(chunk)
    }
    return hash.digest('hex')
  }

This is fairly though. A ~1GB file will take around 3 minutes to generate a checksum with the code above, whereas the built in linux utility
sha256sum
can do the same in 2.5 seconds. Parallelizing this isnt straightforward to me though, since the hash update is blocking
Was this page helpful?