-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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: #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>
- Loading branch information
1 parent
27088cf
commit 152c931
Showing
3 changed files
with
35 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters