source: node_modules/pump/README.md@ 62b2964

finki-main main
Last change on this file since 62b2964 was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 2.4 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
56Note that `pump` attaches error handlers to the streams to do internal error handling, so if `s2` emits an
57error in the above scenario, it will not trigger a `proccess.on('uncaughtException')` if you do not listen for it.
58
59If you want to return a stream that combines *both* s1 and s2 to a single stream use
60[pumpify](https://github.com/mafintosh/pumpify) instead.
61
62## License
63
64MIT
65
66## Related
67
68`pump` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
69
70## For enterprise
71
72Available as part of the Tidelift Subscription.
73
74The maintainers of pump and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-pump?utm_source=npm-pump&utm_medium=referral&utm_campaign=enterprise)
Note: See TracBrowser for help on using the repository browser.