What is @aws-sdk/hash-stream-node?
@aws-sdk/hash-stream-node is a package from the AWS SDK for JavaScript that provides utilities for hashing streams. It is particularly useful for creating hash digests of data streams, which is a common requirement when working with AWS services like S3 for data integrity checks.
Hashing a Stream
This feature allows you to create a hash digest of a data stream using a specified hashing algorithm (e.g., SHA-256). The code sample demonstrates how to read a file as a stream and generate its hash digest.
const { Hash } = require('@aws-sdk/hash-stream-node');
const { createReadStream } = require('fs');
const stream = createReadStream('path/to/file');
const hash = new Hash('sha256');
hash.update(stream);
hash.digest().then(digest => {
console.log('Hash digest:', digest);
});