Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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.
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);
});
Through2 is a tiny wrapper around Node.js streams.Transform (Streams2/3) to avoid explicit subclassing noise. It's similar to pump in facilitating stream operations, but it focuses more on transforming stream data rather than piping and managing stream lifecycle.
Mississippi is a collection of useful stream utilities for Node.js, including pump. It offers a variety of tools for working with streams beyond what pump provides, such as stream concatenation, parallel stream processing, and more, making it a more comprehensive toolkit for stream operations.
pump is a small node module that pipes streams together and destroys all of them if one of them closes.
npm install pump
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
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.
MIT
FAQs
pipe streams together and close all of them if one of them closes
The npm package pump receives a total of 28,895,503 weekly downloads. As such, pump popularity was classified as popular.
We found that pump demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.