basant307/AI_Governance_Project
048
1# pump2 3pump is a small node module that pipes streams together and destroys all of them if one of them closes.4 5```6npm install pump7```8 9[](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 you17 18## Usage19 20Simply pass the streams you want to pipe together to pump and add an optional callback21 22``` js23var 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 source35}, 1000)36```37 38You can use pump to pipe more than two streams together as well39 40``` js41var 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 s254```55 56Note that `pump` attaches error handlers to the streams to do internal error handling, so if `s2` emits an57error 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 use60[pumpify](https://github.com/mafintosh/pumpify) instead.61 62## License63 64MIT65 66## Related67 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 enterprise71 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)75 