Like duplexer (http://npm.im/duplexer) but using streams2
Like duplexer (http://npm.im/duplexer) but using streams2.
duplexer2 is a reimplementation of duplexer using the readable-stream API which is standard in node as of v0.10. Everything largely works the same.
Available via npm:
$ npm install duplexer2
Or via git:
$ git clone git://github.com/deoxxa/duplexer2.git node_modules/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
var duplex = duplexer2 ;
stream.Duplexoptions, as well as the properties described below.
Also see example.js.
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
3-clause BSD. A copy is included with the source.