duplex-through-with-error-handling
v1.0.11
Published
A simple utility to create duplex streams with bidirectional error handling.
Downloads
19
Readme
Duplex Through With Error Handling
A simple utility to create duplex streams with bidirectional error handling.
Uses duplex-through
Installation
To install run:
npm install duplex-through-with-error-handling
Usage
import { duplexThrough } from 'duplex-through-with-error-handling';
const [d1, d2] = duplexThrough({ /* options for duplex streams */ });
// Write data to the stream 1
d1.write('some data');
// Read data from the stream 2
d2.on('data', (data) => {
// data === "some data"
});
d2.on("error", e => {
// e.message === "some error from d1"
});
d1.on("error", e => {
// e.message === "some error from d1"
});
d1.destroy(new Error("some error from d1"))
Features
- Creates duplex streams
- Handles errors bidirectionally to prevent unhandled error events
- Ensures cleanup of error handlers on stream close