node/lib/internal/streams/duplex_base.js
Luigi Pinca df0716921e stream: make Duplex inherits from DuplexBase
Add ability to subclass `stream.Duplex` without inheriting the
"no-half-open enforcer" regardless of the value of the `allowHalfOpen`
option.

PR-URL: https://github.com/nodejs/node/pull/18974
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chen Gang <gangc.cxy@foxmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
2018-03-07 16:05:17 +01:00

31 lines
742 B
JavaScript

'use strict';
const util = require('util');
const Readable = require('_stream_readable');
const Writable = require('_stream_writable');
function DuplexBase(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;
}
util.inherits(DuplexBase, Readable);
{
// Avoid scope creep, the keys array can then be collected.
const keys = Object.keys(Writable.prototype);
for (var v = 0; v < keys.length; v++) {
const method = keys[v];
if (!DuplexBase.prototype[method])
DuplexBase.prototype[method] = Writable.prototype[method];
}
}
module.exports = DuplexBase;