UNPKG

1.15 kBMarkdownView Raw
1# pump
2
3pump is a small node module that pipes streams together and destroys all of them if one of them closes.
4
5 npm install pump
6
7## What problem does it solve?
8
9When using standard `source.pipe(dest)` source will _not_ be destroyed if dest emits close or an error.
10You are also not able to provide a callback to tell when then pipe has finished.
11
12pump does these two things for you
13
14## Usage
15
16Simply pass the streams you want to pipe together to pump and add an optional callback
17
18``` js
19var pump = require('pump');
20var fs = require('fs');
21
22var source = fs.createReadStream('/dev/random');
23var dest = fs.createWriteStream('/dev/null');
24
25pump(source, dest, function(err) {
26 console.log('pipe finished', err);
27});
28
29setTimeout(function() {
30 dest.destroy(); // when dest is closed pump will destroy source
31}, 1000);
32```
33
34You can use pump to pipe more than two streams together as well
35
36``` js
37var transform = someTransformStream();
38
39pump(source, transform, anotherTransform, dest, function(err) {
40 console.log('pipe finished', err);
41});
42```
43
44If `source`, `transform`, `anotherTransform` or `dest` closes all of them will be destroyed.
45
46## License
47
48MIT