Compare the output of two Readable streams using a caller-provided comparison/assertion function.
var assert = ;var fs = ;var streamCompare = ;var stream1 = fs;var stream2 = fs;;
This package is similar to the stream-equal package with several additional features:
- Support for caller-defined comparisons, which can return errors or values not limited to equality.
- Support for both incremental and one-shot comparisons.
- Support for caller-defined data reduction to avoid storing the entire stream history in memory before comparison.
- Makes no assumptions about the type of values read beyond whether they
should be treated as objects (
objectMode) or a stream of Buffers or strings.
- Does not do any coercion of the values read.
- Support for comparing (caller-configurable) events emitted by the streams.
- Support reading in flowing or non-flowing mode.
- Support for optionally aborting comparison on stream errors.
- Support for catching multiple end/error events (within one tick by default, or an optional configurable delay).
- Utility function for creating an incremental comparison and data-reduction
function from a standard data comparison function (e.g.
npm install stream-compare
In order to avoid unnecessary memory use for streams with large amounts of
data and avoid unnecessary delays for streams which produce data slowly, the
output can be compared incrementally and inconclusive output can be removed.
This is done by the incremental function. To make this easier, the utility
makeIncremental creates such a function from a data comparison
function and/or an events comparison function:
var options =incremental: streamCompare;;
Compare Data Values Separately
Sometimes it may be desirable to compare the values returned by
'data' events separately, rather than concatenated together. This can be
done by setting
objectMode: true (even if the values aren't
var options =compare: assertdeepStrictEqualobjectMode: true;;
Compare Data and Event Interleaving
In order to compare the ordering of
'data' events with other events, add
'data' to the
events option and set
'data' events and their arguments will appear with any other
matching events in the
events property of the state object.
var options =compare: assertdeepStrictEqualevents: 'close' 'data' 'end' 'error'readPolicy: 'none';;
Control comparison checkpoints
The returned Promise includes additional methods for controlling the
comparison. A non-incremental compare can be run before both streams end
.checkpoint(). Additionally, the comparison can be concluded before
both streams end using
.end(). The full details are available in the API
var PassThrough = PassThrough;var stream1 = ;var stream2 = ;var comparison = ;comparison;stream1;stream2;process;
More examples can be found in the test specifications.
For the details of using this module as a library, see the API Documentation.
Contributions are welcome and very much appreciated! Please add tests to
cover any changes and ensure
npm test passes.
If the desired change is large, complex, backwards-incompatible, can have significantly differing implementations, or may not be in scope for this project, opening an issue before writing the code can avoid frustration and save a lot of time and effort.
This package is available under the terms of the MIT License.