1 var stream = require("readable-stream");
3 var duplex2 = module.exports = function duplex2(options, writable, readable) {
4 return new DuplexWrapper(options, writable, readable);
7 var DuplexWrapper = exports.DuplexWrapper = function DuplexWrapper(options, writable, readable) {
8 if (typeof readable === "undefined") {
14 options = options || {};
15 options.objectMode = true;
17 stream.Duplex.call(this, options);
19 this._bubbleErrors = (typeof options.bubbleErrors === "undefined") || !!options.bubbleErrors;
21 this._writable = writable;
22 this._readable = readable;
26 writable.once("finish", function() {
30 this.once("finish", function() {
34 readable.on("data", function(e) {
40 readable.once("end", function() {
41 return self.push(null);
44 if (this._bubbleErrors) {
45 writable.on("error", function(err) {
46 return self.emit("error", err);
49 readable.on("error", function(err) {
50 return self.emit("error", err);
54 DuplexWrapper.prototype = Object.create(stream.Duplex.prototype, {constructor: {value: DuplexWrapper}});
56 DuplexWrapper.prototype._write = function _write(input, encoding, done) {
57 this._writable.write(input, encoding, done);
60 DuplexWrapper.prototype._read = function _read(n) {
61 this._readable.resume();