react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / duplexer2 / index.js
80709 viewsvar stream = require("readable-stream");12var duplex2 = module.exports = function duplex2(options, writable, readable) {3return new DuplexWrapper(options, writable, readable);4};56var DuplexWrapper = exports.DuplexWrapper = function DuplexWrapper(options, writable, readable) {7if (typeof readable === "undefined") {8readable = writable;9writable = options;10options = null;11}1213options = options || {};14options.objectMode = true;1516stream.Duplex.call(this, options);1718this._bubbleErrors = (typeof options.bubbleErrors === "undefined") || !!options.bubbleErrors;1920this._writable = writable;21this._readable = readable;2223var self = this;2425writable.once("finish", function() {26self.end();27});2829this.once("finish", function() {30writable.end();31});3233readable.on("data", function(e) {34if (!self.push(e)) {35readable.pause();36}37});3839readable.once("end", function() {40return self.push(null);41});4243if (this._bubbleErrors) {44writable.on("error", function(err) {45return self.emit("error", err);46});4748readable.on("error", function(err) {49return self.emit("error", err);50});51}52};53DuplexWrapper.prototype = Object.create(stream.Duplex.prototype, {constructor: {value: DuplexWrapper}});5455DuplexWrapper.prototype._write = function _write(input, encoding, done) {56this._writable.write(input, encoding, done);57};5859DuplexWrapper.prototype._read = function _read(n) {60this._readable.resume();61};626364