UNPKG

1.61 kBMarkdownView Raw
1# pumpify
2
3Combine an array of streams into a single duplex stream using [pump](https://github.com/mafintosh/pump) and [duplexify](https://github.com/mafintosh/duplexify).
4If one of the streams closes/errors all streams in the pipeline will be destroyed.
5
6```
7npm install pumpify
8```
9
10[![build status](http://img.shields.io/travis/mafintosh/pumpify.svg?style=flat)](http://travis-ci.org/mafintosh/pumpify)
11
12## Usage
13
14Pass the streams you want to pipe together to pumpify `pipeline = pumpify(s1, s2, s3, ...)`.
15`pipeline` is a duplex stream that writes to the first streams and reads from the last one.
16Streams are piped together using [pump](https://github.com/mafintosh/pump) so if one of them closes
17all streams will be destroyed.
18
19``` js
20var pumpify = require('pumpify')
21var tar = require('tar-fs')
22var zlib = require('zlib')
23var fs = require('fs')
24
25var untar = pumpify(zlib.createGunzip(), tar.extract('output-folder'))
26
27fs.createReadStream('some-gzipped-tarball.tgz').pipe(untar)
28```
29
30If you are pumping object streams together use `pipeline = pumpify.obj(s1, s2, ...)`.
31Call `pipeline.destroy()` to destroy the pipeline (including the streams passed to pumpify).
32
33### Using `setPipeline(s1, s2, ...)`
34
35Similar to [duplexify](https://github.com/mafintosh/duplexify) you can also define the pipeline asynchronously using `setPipeline(s1, s2, ...)`
36
37``` js
38var untar = pumpify()
39
40setTimeout(function() {
41 // will start draining the input now
42 untar.setPipeline(zlib.createGunzip(), tar.extract('output-folder'))
43}, 1000)
44
45fs.createReadStream('some-gzipped-tarball.tgz').pipe(untar)
46```
47
48## License
49
50MIT
\No newline at end of file