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.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. # pump
  2. pump is a small node module that pipes streams together and destroys all of them if one of them closes.
  3. ```
  4. npm install pump
  5. ```
  6. [![build status](http://img.shields.io/travis/mafintosh/pump.svg?style=flat)](http://travis-ci.org/mafintosh/pump)
  7. ## What problem does it solve?
  8. When using standard `source.pipe(dest)` source will _not_ be destroyed if dest emits close or an error.
  9. You are also not able to provide a callback to tell when then pipe has finished.
  10. pump does these two things for you
  11. ## Usage
  12. Simply pass the streams you want to pipe together to pump and add an optional callback
  13. ``` js
  14. var pump = require('pump')
  15. var fs = require('fs')
  16. var source = fs.createReadStream('/dev/random')
  17. var dest = fs.createWriteStream('/dev/null')
  18. pump(source, dest, function(err) {
  19. console.log('pipe finished', err)
  20. })
  21. setTimeout(function() {
  22. dest.destroy() // when dest is closed pump will destroy source
  23. }, 1000)
  24. ```
  25. You can use pump to pipe more than two streams together as well
  26. ``` js
  27. var transform = someTransformStream()
  28. pump(source, transform, anotherTransform, dest, function(err) {
  29. console.log('pipe finished', err)
  30. })
  31. ```
  32. If `source`, `transform`, `anotherTransform` or `dest` closes all of them will be destroyed.
  33. ## License
  34. MIT
  35. ## Related
  36. `pump` is part of the [mississippi stream utility collection](https://github.com/maxogden/mississippi) which includes more useful stream modules similar to this one.