source: trip-planner-front/node_modules/pump/README.md@ 6a3a178

Last change on this file since 6a3a178 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
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```
6npm install pump
7```
8
9[![build status](http://img.shields.io/travis/mafintosh/pump.svg?style=flat)](http://travis-ci.org/mafintosh/pump)
10
11## What problem does it solve?
12
13When using standard `source.pipe(dest)` source will _not_ be destroyed if dest emits close or an error.
14You are also not able to provide a callback to tell when then pipe has finished.
15
16pump does these two things for you
17
18## Usage
19
20Simply pass the streams you want to pipe together to pump and add an optional callback
21
22``` js
23var pump = require('pump')
24var fs = require('fs')
25
26var source = fs.createReadStream('/dev/random')
27var dest = fs.createWriteStream('/dev/null')
28
29pump(source, dest, function(err) {
30 console.log('pipe finished', err)
31})
32
33setTimeout(function() {
34 dest.destroy() // when dest is closed pump will destroy source
35}, 1000)
36```
37
38You can use pump to pipe more than two streams together as well
39
40``` js
41var transform = someTransformStream()
42
43pump(source, transform, anotherTransform, dest, function(err) {
44 console.log('pipe finished', err)
45})
46```
47
48If `source`, `transform`, `anotherTransform` or `dest` closes all of them will be destroyed.
49
50Similarly to `stream.pipe()`, `pump()` returns the last stream passed in, so you can do:
51
52```
53return pump(s1, s2) // returns s2
54```
55
56If you want to return a stream that combines *both* s1 and s2 to a single stream use
57[pumpify](https://github.com/mafintosh/pumpify) instead.
58
59## License
60
61MIT
62
63## Related
64
65`pump` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
Note: See TracBrowser for help on using the repository browser.