summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/readable-stream/lib/_stream_duplex.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/readable-stream/lib/_stream_duplex.js')
-rw-r--r--deps/npm/node_modules/readable-stream/lib/_stream_duplex.js96
1 files changed, 52 insertions, 44 deletions
diff --git a/deps/npm/node_modules/readable-stream/lib/_stream_duplex.js b/deps/npm/node_modules/readable-stream/lib/_stream_duplex.js
index a1ca813e5a..6752519225 100644
--- a/deps/npm/node_modules/readable-stream/lib/_stream_duplex.js
+++ b/deps/npm/node_modules/readable-stream/lib/_stream_duplex.js
@@ -18,43 +18,37 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
// a duplex stream is just a stream that is both readable and writable.
// Since JS doesn't have multiple prototypal inheritance, this class
// prototypally inherits from Readable, and then parasitically from
// Writable.
-
'use strict';
-
/*<replacement>*/
-var pna = require('process-nextick-args');
-/*</replacement>*/
-
-/*<replacement>*/
var objectKeys = Object.keys || function (obj) {
var keys = [];
+
for (var key in obj) {
keys.push(key);
- }return keys;
+ }
+
+ return keys;
};
/*</replacement>*/
-module.exports = Duplex;
-/*<replacement>*/
-var util = require('core-util-is');
-util.inherits = require('inherits');
-/*</replacement>*/
+module.exports = Duplex;
var Readable = require('./_stream_readable');
+
var Writable = require('./_stream_writable');
-util.inherits(Duplex, Readable);
+require('inherits')(Duplex, Readable);
{
- // avoid scope creep, the keys array can then be collected
+ // Allow the keys array to be GC'ed.
var keys = objectKeys(Writable.prototype);
+
for (var v = 0; v < keys.length; v++) {
var method = keys[v];
if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method];
@@ -63,18 +57,19 @@ util.inherits(Duplex, Readable);
function Duplex(options) {
if (!(this instanceof Duplex)) return new Duplex(options);
-
Readable.call(this, options);
Writable.call(this, options);
-
- if (options && options.readable === false) this.readable = false;
-
- if (options && options.writable === false) this.writable = false;
-
this.allowHalfOpen = true;
- if (options && options.allowHalfOpen === false) this.allowHalfOpen = false;
- this.once('end', onend);
+ if (options) {
+ if (options.readable === false) this.readable = false;
+ if (options.writable === false) this.writable = false;
+
+ if (options.allowHalfOpen === false) {
+ this.allowHalfOpen = false;
+ this.once('end', onend);
+ }
+ }
}
Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
@@ -82,20 +77,35 @@ Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
- get: function () {
+ get: function get() {
return this._writableState.highWaterMark;
}
});
+Object.defineProperty(Duplex.prototype, 'writableBuffer', {
+ // making it explicit this property is not enumerable
+ // because otherwise some prototype manipulation in
+ // userland will fail
+ enumerable: false,
+ get: function get() {
+ return this._writableState && this._writableState.getBuffer();
+ }
+});
+Object.defineProperty(Duplex.prototype, 'writableLength', {
+ // making it explicit this property is not enumerable
+ // because otherwise some prototype manipulation in
+ // userland will fail
+ enumerable: false,
+ get: function get() {
+ return this._writableState.length;
+ }
+}); // the no-half-open enforcer
-// the no-half-open enforcer
function onend() {
- // if we allow half-open state, or if the writable side ended,
- // then we're ok.
- if (this.allowHalfOpen || this._writableState.ended) return;
-
- // no more data can be written.
+ // If the writable side ended, then we're ok.
+ if (this._writableState.ended) return; // no more data can be written.
// But allow more writes to happen in this tick.
- pna.nextTick(onEndNT, this);
+
+ process.nextTick(onEndNT, this);
}
function onEndNT(self) {
@@ -103,29 +113,27 @@ function onEndNT(self) {
}
Object.defineProperty(Duplex.prototype, 'destroyed', {
- get: function () {
+ // making it explicit this property is not enumerable
+ // because otherwise some prototype manipulation in
+ // userland will fail
+ enumerable: false,
+ get: function get() {
if (this._readableState === undefined || this._writableState === undefined) {
return false;
}
+
return this._readableState.destroyed && this._writableState.destroyed;
},
- set: function (value) {
+ set: function set(value) {
// we ignore the value if the stream
// has not been initialized yet
if (this._readableState === undefined || this._writableState === undefined) {
return;
- }
-
- // backward compatibility, the user is explicitly
+ } // backward compatibility, the user is explicitly
// managing destroyed
+
+
this._readableState.destroyed = value;
this._writableState.destroyed = value;
}
-});
-
-Duplex.prototype._destroy = function (err, cb) {
- this.push(null);
- this.end();
-
- pna.nextTick(cb, err);
-}; \ No newline at end of file
+}); \ No newline at end of file