Registry / testing / stream-equal

stream-equal

JSON →
library2.0.1jsnpmunverified

Stream Equal is a Node.js utility package designed to test if two readable streams emit the exact same data. The package is currently stable at version 2.0.1, with recent updates indicating active maintenance, including a fix for CommonJS imports. It operates by comparing streams chunk-by-chunk, pausing them as needed to keep them synchronized. This method is highlighted as being more efficient in terms of memory and CPU usage for large files compared to buffering entire stream contents or computing cryptographic hashes, especially when the streams are not equal. Its primary application is in testing scenarios where stream content verification is crucial, offering a performance-optimized alternative to traditional comparison methods.

npm install stream-equal
INSTALL
IMPORT
SIG · STREAM-EQUAL
S
stream-equal
testingjavascriptv2.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

streamEqual
import streamEqual from 'stream-equal';
import { streamEqual } from 'stream-equal';
This package uses a default export for the primary function.
streamEqual
const streamEqual = require('stream-equal');
CommonJS `require` was fully supported and fixed in v2.0.1.
streamEqual
const streamEqual = require('stream-equal'); // For CJS modules
const streamEqual = require('stream-equal').default; // Not needed after v2.0.1 fix
Prior to v2.0.1, CJS users might have needed `.default` due to bundling issues, which is now resolved.

Demonstrates how to import and use `streamEqual` with async/await to compare two readable streams, showing both equal and unequal cases.

import streamEqual from 'stream-equal'; import { Readable } from 'stream'; async function compareStreams() { // Create two identical streams from buffers const stream1 = Readable.from(Buffer.from('Hello, World!')); const stream2 = Readable.from(Buffer.from('Hello, World!')); // Create two different streams const stream3 = Readable.from(Buffer.from('Hello, Universe!')); const stream4 = Readable.from(Buffer.from('Hello, World!')); const areEqual1 = await streamEqual(stream1, stream2); console.log('Stream 1 and Stream 2 are equal:', areEqual1); // Expected: true const areEqual2 = await streamEqual(stream3, stream4); console.log('Stream 3 and Stream 4 are equal:', areEqual2); // Expected: false } compareStreams().catch(console.error);
Debug
Known issues
breakingVersion 2.0.0 removed callback support. All usages must now utilize Promises and `async/await` syntax for stream comparison.
fix
Rewrite stream comparison logic to `await streamEqual(stream1, stream2)` instead of `streamEqual(stream1, stream2, callback)`.
affects: >=2.0.0
gotchaWhen using CommonJS `require` in versions prior to 2.0.1, there could be issues importing the default export, sometimes requiring `.default`.
fix
Update to `stream-equal@2.0.1` or newer. If unable to update, try `const streamEqual = require('stream-equal').default;` as a workaround, though it's not the recommended long-term solution.
affects: <2.0.1
Errors
Common errors & fixes
TypeError: streamEqual is not a function
Attempting to import `streamEqual` using `require` in a version prior to 2.0.1, or using named import syntax for a default export.
fix
Ensure you are on `stream-equal@2.0.1` or newer for robust CJS `require`. For ESM, use `import streamEqual from 'stream-equal';`. For older CJS versions, try `const streamEqual = require('stream-equal').default;`.
TypeError: Cannot read properties of undefined (reading 'then')
Attempting to use `streamEqual` with a callback in versions >= 2.0.0, which no longer support callback-based asynchronous operations.
fix
Remove the callback function and use `await` with the `streamEqual` promise directly: `const result = await streamEqual(stream1, stream2);`.
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
10
OpenAI (training)
1
Resources
stream-equal — npm install stream-equal · libregistry