Socket
Socket
Sign inDemoInstall

pump

Package Overview
Dependencies
3
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    pump

pipe streams together and close all of them if one of them closes


Version published
Weekly downloads
40M
increased by2.01%
Maintainers
1
Install size
23.9 kB
Created
Weekly downloads
 

Package description

What is pump?

The pump npm package is a small node module that pipes streams together and destroys all of them if one of them closes. It is particularly useful for preventing memory leaks when piping together streams and handling errors properly in Node.js applications.

What are pump's main functionalities?

Piping streams together with error handling

This code demonstrates how to use pump to pipe data from a readable stream to a writable stream, such as from a file to another file, with error handling. If an error occurs in any of the streams, pump ensures that all streams are properly closed to prevent memory leaks.

const pump = require('pump');
const fs = require('fs');
const source = fs.createReadStream('/path/to/source');
const destination = fs.createWriteStream('/path/to/dest');
pump(source, destination, function(err) {
  console.log('Pipe finished', err);
});

Other packages similar to pump

Readme

Source

pump

pump is a small node module that pipes streams together and destroys all of them if one of them closes.

npm install pump

build status

What problem does it solve?

When using standard source.pipe(dest) source will not be destroyed if dest emits close or an error. You are also not able to provide a callback to tell when then pipe has finished.

pump does these two things for you

Usage

Simply pass the streams you want to pipe together to pump and add an optional callback

var pump = require('pump')
var fs = require('fs')

var source = fs.createReadStream('/dev/random')
var dest = fs.createWriteStream('/dev/null')

pump(source, dest, function(err) {
  console.log('pipe finished', err)
})

setTimeout(function() {
  dest.destroy() // when dest is closed pump will destroy source
}, 1000)

You can use pump to pipe more than two streams together as well

var transform = someTransformStream()

pump(source, transform, anotherTransform, dest, function(err) {
  console.log('pipe finished', err)
})

If source, transform, anotherTransform or dest closes all of them will be destroyed.

Similarly to stream.pipe(), pump() returns the last stream passed in, so you can do:

return pump(s1, s2) // returns s2

If you want to return a stream that combines both s1 and s2 to a single stream use pumpify instead.

License

MIT

pump is part of the mississippi stream utility collection which includes more useful stream modules similar to this one.

Keywords

FAQs

Last updated on 31 Jan 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc