123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 'use strict';
- var pna = require('process-nextick-args');
- var objectKeys = Object.keys || function (obj) {
- var keys = [];
- for (var key in obj) {
- keys.push(key);
- }return keys;
- };
- module.exports = Duplex;
- var util = Object.create(require('core-util-is'));
- util.inherits = require('inherits');
- var Readable = require('./_stream_readable');
- var Writable = require('./_stream_writable');
- util.inherits(Duplex, Readable);
- {
-
- 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];
- }
- }
- 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);
- }
- Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', {
-
-
-
- enumerable: false,
- get: function () {
- return this._writableState.highWaterMark;
- }
- });
- function onend() {
-
-
- if (this.allowHalfOpen || this._writableState.ended) return;
-
-
- pna.nextTick(onEndNT, this);
- }
- function onEndNT(self) {
- self.end();
- }
- Object.defineProperty(Duplex.prototype, 'destroyed', {
- get: function () {
- if (this._readableState === undefined || this._writableState === undefined) {
- return false;
- }
- return this._readableState.destroyed && this._writableState.destroyed;
- },
- set: function (value) {
-
-
- if (this._readableState === undefined || this._writableState === undefined) {
- return;
- }
-
-
- this._readableState.destroyed = value;
- this._writableState.destroyed = value;
- }
- });
- Duplex.prototype._destroy = function (err, cb) {
- this.push(null);
- this.end();
- pna.nextTick(cb, err);
- };
|