pump

Pipe Node.js streams together and destroy all of them if one closes

Library
npm
v3.0.4
918stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
34/100Needs Attention
Development Activity4
Maintenance0
Community44
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture78
Code Quality76
Innovation72
Learning Curve92

pump is a small Node.js module that pipes streams together and destroys all of them if any one closes or errors. It fixes two long-standing problems with the built-in source.pipe(dest): the source stream is not destroyed when the destination emits close or an error, and there is no way to know when the pipeline has finished.

With pump you pass any number of streams and an optional callback that fires once the pipe completes or fails. It attaches internal error handlers so a failure in one stream reliably tears down the rest without crashing the process, making stream pipelines leak-free and predictable.

What You Get

  • A single function that pipes two or more streams together in one call
  • Automatic destruction of all streams when any one of them closes or errors
  • A completion callback that reports success or the first error
  • Return of the last stream passed in, matching stream.pipe() ergonomics
  • Internal error handlers that prevent unhandled stream errors from crashing the process

Common Use Cases

  • Safely piping a file read stream through transforms to a write stream
  • Ensuring temporary or upstream streams are cleaned up when a download or upload aborts
  • Getting a reliable done/error callback for multi-stage stream processing
  • Replacing fragile source.pipe(dest) chains that leak file descriptors on error

Under The Hood

Architecture - pump is a single ~86-line index.js. It wraps each stream with a destroyer that force-closes it, uses end-of-stream (eos) to detect when each stream finishes or errors, and once to ensure the user callback fires exactly one time. When any stream in the chain signals close or error, pump walks the list and destroys the remaining streams, then invokes the callback with the first error encountered.

Tech Stack - Pure JavaScript for Node.js with two tiny runtime dependencies: end-of-stream (to normalize stream completion detection across stream implementations) and once (to guard the callback). There is no build step; the same code is exercised in both Node and browser test harnesses.

Code Quality - Despite its size, the module ships dedicated Node and browser test files (test-node.js, test-browser.js) run via the npm test script, plus a SECURITY.md. The logic is deliberately minimal and defensive, attaching its own error handlers so that stream errors are captured rather than crashing the process. Its stability is proven by tens of millions of weekly downloads.

API Design - The API is about as small as it gets: call pump with the streams to connect and an optional trailing callback. It mirrors stream.pipe() by returning the last stream, so it slots into existing code with minimal friction. The single documented behavior (destroy-all-on-close plus a done callback) makes the learning curve nearly flat.”

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search