1 # duplexer3 [![Build Status](https://travis-ci.org/floatdrop/duplexer3.svg?branch=master)](https://travis-ci.org/floatdrop/duplexer3) [![Coverage Status](https://coveralls.io/repos/floatdrop/duplexer3/badge.svg?branch=master&service=github)](https://coveralls.io/github/floatdrop/duplexer3?branch=master)
3 Like [duplexer2](https://github.com/deoxxa/duplexer2) but using Streams3 without readable-stream dependency
6 var stream = require("stream");
8 var duplexer3 = require("duplexer3");
10 var writable = new stream.Writable({objectMode: true}),
11 readable = new stream.Readable({objectMode: true});
13 writable._write = function _write(input, encoding, done) {
14 if (readable.push(input)) {
17 readable.once("drain", done);
21 readable._read = function _read(n) {
25 // simulate the readable thing closing after a bit
26 writable.once("finish", function() {
27 setTimeout(function() {
32 var duplex = duplexer3(writable, readable);
34 duplex.on("data", function(e) {
35 console.log("got data", JSON.stringify(e));
38 duplex.on("finish", function() {
39 console.log("got finish event");
42 duplex.on("end", function() {
43 console.log("got end event");
46 duplex.write("oh, hi there", function() {
47 console.log("finished writing");
50 duplex.end(function() {
51 console.log("finished ending");
56 got data "oh, hi there"
65 This is a reimplementation of [duplexer](https://www.npmjs.com/package/duplexer) using the
66 Streams3 API which is standard in Node as of v4. Everything largely
73 [Available via `npm`](https://docs.npmjs.com/cli/install):
83 Creates a new `DuplexWrapper` object, which is the actual class that implements
84 most of the fun stuff. All that fun stuff is hidden. DON'T LOOK.
87 duplexer3([options], writable, readable)
91 const duplex = duplexer3(new stream.Writable(), new stream.Readable());
96 * __options__ - an object specifying the regular `stream.Duplex` options, as
97 well as the properties described below.
98 * __writable__ - a writable stream
99 * __readable__ - a readable stream
103 * __bubbleErrors__ - a boolean value that specifies whether to bubble errors
104 from the underlying readable/writable streams. Default is `true`.
109 3-clause BSD. [A copy](./LICENSE) is included with the source.
113 * GitHub ([deoxxa](http://github.com/deoxxa))
114 * Twitter ([@deoxxa](http://twitter.com/deoxxa))
115 * Email ([deoxxa@fknsrs.biz](mailto:deoxxa@fknsrs.biz))