1 | # node-stream-equal
|
2 |
|
3 | Test 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
|
11 | const streamEqual = require('stream-equal');
|
12 | const fs = require('fs');
|
13 |
|
14 | let readStream1 = fs.createReadStream(file);
|
15 | let readStream2 = fs.createReadStream(file);
|
16 | let equal = await streamEqual(readStream1, readStream2);
|
17 | ```
|
18 |
|
19 |
|
20 | # Motive
|
21 | Useful 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 |
|
23 | You 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 |
|
29 | A 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
|
38 | Tests are written with [mocha](https://mochajs.org)
|
39 |
|
40 | ```bash
|
41 | npm test
|
42 | ```
|