Composable streams. Present a distinct readable stream and a distinct writable stream as a single Stream for reading/writing.
Composes two distinct readable and writable streams into one cohesive Stream. Why would you want to do this? I honestly have no idea. You'd have to be really stupid or something.
npm install duplex-stream
var DuplexStream = require("duplex-stream"); var myDuplexStream = new DuplexStream(aReadableStream, aWritableStream);
The DuplexStream should behave exactly how you'd expect.
// Probably because of this: console.log((new DuplexStream()) instanceof Stream); // -> true
That is, when events occur on the underlying streams, they occur on the DuplexStream.
dataevent is emitted on DuplexStream
endevent occurs on underlying readable, DuplexStream marks itself as unreadable but can still be written to (if it's not already been ended).
destroySoon()on the duplex stream will destroy readable stream immediately and tell writable stream to destroy as soon as it can.
One little "gotcha" though,
close won't be emitted on the DuplexStream until both underlying streams are closed.
DuplexStream is just a silly little convenience. An (unnecessary) abstraction. I use it for composing automated tests that deal with Streams, along with my node-stream-buffer project.