Like duplexer but using streams3
Like duplexer but using Streams3
var stream = require"stream";var duplexer2 = require"duplexer2";var writable = objectMode: truereadable = objectMode: true;writable_write =if readablepushinputreturn done;elsereadableonce"drain" done;;readable_read =// no-op;// simulate the readable thing closing after a bitwritableonce"finish"setTimeoutreadablepushnull;500;;var duplex = duplexer2writable readable;duplexon"data"console.log"got data" JSONstringifye;;duplexon"finish"console.log"got finish event";;duplexon"end"console.log"got end event";;duplexwrite"oh, hi there"console.log"finished writing";;duplexendconsole.log"finished ending";;
got data "oh, hi there"finished writinggot finish eventfinished endinggot end event
This is a reimplementation of duplexer using the Streams3 API which is standard in Node as of v4. Everything largely works the same.
$ npm i duplexer2
Creates a new
DuplexWrapper object, which is the actual class that implements
most of the fun stuff. All that fun stuff is hidden. DON'T LOOK.
duplexer2options writable readable
const duplex = duplexer2 ;
stream.Duplexoptions, as well as the properties described below.
3-clause BSD. A copy is included with the source.