1
|
# pumpify
|
2
|
|
3
|
Combine an array of streams into a single duplex stream using [pump](https://github.com/mafintosh/pump) and [duplexify](https://github.com/mafintosh/duplexify).
|
4
|
If one of the streams closes/errors all streams in the pipeline will be destroyed.
|
5
|
|
6
|
```
|
7
|
npm 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
|
|
14
|
Pass 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.
|
16
|
Streams are piped together using [pump](https://github.com/mafintosh/pump) so if one of them closes
|
17
|
all streams will be destroyed.
|
18
|
|
19
|
``` js
|
20
|
var pumpify = require('pumpify')
|
21
|
var tar = require('tar-fs')
|
22
|
var zlib = require('zlib')
|
23
|
var fs = require('fs')
|
24
|
|
25
|
var untar = pumpify(zlib.createGunzip(), tar.extract('output-folder'))
|
26
|
// you can also pass an array instead
|
27
|
// var untar = pumpify([zlib.createGunzip(), tar.extract('output-folder')])
|
28
|
|
29
|
fs.createReadStream('some-gzipped-tarball.tgz').pipe(untar)
|
30
|
```
|
31
|
|
32
|
If you are pumping object streams together use `pipeline = pumpify.obj(s1, s2, ...)`.
|
33
|
Call `pipeline.destroy()` to destroy the pipeline (including the streams passed to pumpify).
|
34
|
|
35
|
### Using `setPipeline(s1, s2, ...)`
|
36
|
|
37
|
Similar to [duplexify](https://github.com/mafintosh/duplexify) you can also define the pipeline asynchronously using `setPipeline(s1, s2, ...)`
|
38
|
|
39
|
``` js
|
40
|
var untar = pumpify()
|
41
|
|
42
|
setTimeout(function() {
|
43
|
// will start draining the input now
|
44
|
untar.setPipeline(zlib.createGunzip(), tar.extract('output-folder'))
|
45
|
}, 1000)
|
46
|
|
47
|
fs.createReadStream('some-gzipped-tarball.tgz').pipe(untar)
|
48
|
```
|
49
|
|
50
|
## License
|
51
|
|
52
|
MIT
|
53
|
|
54
|
## Related
|
55
|
|
56
|
`pumpify` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.
|