-
Notifications
You must be signed in to change notification settings - Fork 30k
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 <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Chen Gang <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
- 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