pump
Pipe Node.js streams together and destroy all of them if one closes
Repository Health
Technical Analysis
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.”
Used by 3 apps in this directory
APITable
Low Code Platforms · Databases
API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.
melty
Developer Tools · AI Code Assistants · Code Editors
The AI code editor where every chat message is a git commit you can revert, branch, or squash
Void
AI Code Assistants · Code Editors · Automation
Open-source AI code editor with direct LLM integration and data privacy