You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.9KB

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