UNPKG

1.29 kBMarkdownView Raw
1# node-stream-equal
2
3Test that two readable streams are equal to each other.
4
5[![Dependency Status](https://david-dm.org/fent/node-stream-equal.svg)](https://david-dm.org/fent/node-stream-equal)
6[![codecov](https://codecov.io/gh/fent/node-stream-equal/branch/master/graph/badge.svg)](https://codecov.io/gh/fent/node-stream-equal)
7
8# Usage
9
10```js
11const streamEqual = require('stream-equal');
12const fs = require('fs');
13
14let readStream1 = fs.createReadStream(file);
15let readStream2 = fs.createReadStream(file);
16let equal = await streamEqual(readStream1, readStream2);
17```
18
19
20# Motive
21Useful for testing. This method of comparing is faster and uses less memory than buffering entire streams and comparing their content, specially for bigger files.
22
23You could also get the hash sum of a stream to test it against another stream. But that would take up more CPU due to the hashing and would require a bit more data to be read if they are not equal.
24
25
26# API
27### async streamEqual(readStream1, readStream2)
28
29A function that compares each `data` event on both streams, pausing when needed to keep them in sync. Returns a proimse that resolves to either `true` or `false`.
30
31
32# Install
33
34 npm install stream-equal
35
36
37# Tests
38Tests are written with [mocha](https://mochajs.org)
39
40```bash
41npm test
42```