2.0.0 • Published 3 years ago

@mangosteen/digest-stream v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

digest-stream

Compute hash or HMAC using a transform stream.

Installation

With npm do:

$ npm install @mangosteen/digest-stream

Usage

import { DigestStream } from '@mangosteen/digest-stream';
import crypto from 'crypto';
import fs from 'fs';
import { promisify } from 'util';

const pipeline = promisify(stream.pipeline);

(async () => {
    const digestStream = new DigestStream({
        digest: crypto.createHash('sha256'),
    });

    await pipeline([
        fs.createReadStream('./shakespeare.txt'),
        digestStream,
        // ...
    ]);

    const sha256: string = digestStream.digest().toString('hex');
    console.log(sha256);
})();