digest

Compute cryptographic hash digests while streaming data.

Install

npm install @datastream/digest

digestStream PassThrough async (browser)

Computes a hash digest of all data passing through. The stream is async in the browser (returns a Promise) because it uses hash-wasm.

Options

OptionTypeDefaultDescription
algorithmstringHash algorithm (see table below)
resultKeystring"digest"Key in pipeline result

Supported algorithms

AlgorithmNode.jsBrowser
SHA2-256node:cryptohash-wasm
SHA2-384node:cryptohash-wasm
SHA2-512node:cryptohash-wasm
SHA3-256hash-wasm
SHA3-384hash-wasm
SHA3-512hash-wasm

Result

'SHA2-256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'

Example

import { pipeline } from '@datastream/core'
import { fileReadStream } from '@datastream/file'
import { digestStream } from '@datastream/digest'

// Node.js — synchronous
const digest = digestStream({ algorithm: 'SHA2-256' })

const result = await pipeline([
  fileReadStream({ path: './data.csv' }),
  digest,
])

console.log(result)
// { digest: 'SHA2-256:e3b0c4429...' }
// Browser — async, must await
const digest = await digestStream({ algorithm: 'SHA2-256' })