1 duplexer2 [![build status](https://travis-ci.org/deoxxa/duplexer2.png)](https://travis-ci.org/deoxxa/fork)
4 Like duplexer (http://npm.im/duplexer) but using streams2.
9 duplexer2 is a reimplementation of [duplexer](http://npm.im/duplexer) using the
10 readable-stream API which is standard in node as of v0.10. Everything largely
16 Available via [npm](http://npmjs.org/):
18 > $ npm install duplexer2
22 > $ git clone git://github.com/deoxxa/duplexer2.git node_modules/duplexer2
29 Creates a new `DuplexWrapper` object, which is the actual class that implements
30 most of the fun stuff. All that fun stuff is hidden. DON'T LOOK.
33 duplexer2([options], writable, readable)
37 var duplex = duplexer2(new stream.Writable(), new stream.Readable());
42 * __options__ - an object specifying the regular `stream.Duplex` options, as
43 well as the properties described below.
44 * __writable__ - a writable stream
45 * __readable__ - a readable stream
49 * __bubbleErrors__ - a boolean value that specifies whether to bubble errors
50 from the underlying readable/writable streams. Default is `true`.
55 Also see [example.js](https://github.com/deoxxa/duplexer2/blob/master/example.js).
60 var stream = require("stream");
62 var duplexer2 = require("duplexer2");
64 var writable = new stream.Writable({objectMode: true}),
65 readable = new stream.Readable({objectMode: true});
67 writable._write = function _write(input, encoding, done) {
68 if (readable.push(input)) {
71 readable.once("drain", done);
75 readable._read = function _read(n) {
79 // simulate the readable thing closing after a bit
80 writable.once("finish", function() {
81 setTimeout(function() {
86 var duplex = duplexer2(writable, readable);
88 duplex.on("data", function(e) {
89 console.log("got data", JSON.stringify(e));
92 duplex.on("finish", function() {
93 console.log("got finish event");
96 duplex.on("end", function() {
97 console.log("got end event");
100 duplex.write("oh, hi there", function() {
101 console.log("finished writing");
104 duplex.end(function() {
105 console.log("finished ending");
112 got data "oh, hi there"
122 3-clause BSD. A copy is included with the source.
127 * GitHub ([deoxxa](http://github.com/deoxxa))
128 * Twitter ([@deoxxa](http://twitter.com/deoxxa))
129 * Email ([deoxxa@fknsrs.biz](mailto:deoxxa@fknsrs.biz))