GeezerVison is showing github.com — stream: make Duplex inherits from DuplexBase · nodejs/node@152c931
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/_stream_duplex.js +4-22Lines changed: 4 additions & 22 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
29 | 29 | module.exports = Duplex; |
30 | 30 |
|
31 | 31 | const util = require('util'); |
32 | | -const Readable = require('_stream_readable'); |
33 | | -const Writable = require('_stream_writable'); |
34 | | - |
35 | | -util.inherits(Duplex, Readable); |
36 | | - |
37 | | -{ |
38 | | - // avoid scope creep, the keys array can then be collected |
39 | | - const keys = Object.keys(Writable.prototype); |
40 | | - for (var v = 0; v < keys.length; v++) { |
41 | | - const method = keys[v]; |
42 | | - if (!Duplex.prototype[method]) |
43 | | - Duplex.prototype[method] = Writable.prototype[method]; |
44 | | - } |
45 | | -} |
| 32 | +const DuplexBase = require('internal/streams/duplex_base'); |
| 33 | + |
| 34 | +util.inherits(Duplex, DuplexBase); |
46 | 35 |
|
47 | 36 | function Duplex(options) { |
48 | 37 | if (!(this instanceof Duplex)) |
49 | 38 | return new Duplex(options); |
50 | 39 |
|
51 | | - Readable.call(this, options); |
52 | | - Writable.call(this, options); |
53 | | - |
54 | | - if (options && options.readable === false) |
55 | | - this.readable = false; |
56 | | - |
57 | | - if (options && options.writable === false) |
58 | | - this.writable = false; |
| 40 | + DuplexBase.call(this, options); |
59 | 41 |
|
60 | 42 | this.allowHalfOpen = true; |
61 | 43 | if (options && options.allowHalfOpen === false) { |
|
Collapse file
Copy file name to clipboard +30Lines changed: 30 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const util = require('util'); |
| 4 | +const Readable = require('_stream_readable'); |
| 5 | +const Writable = require('_stream_writable'); |
| 6 | + |
| 7 | +function DuplexBase(options) { |
| 8 | + Readable.call(this, options); |
| 9 | + Writable.call(this, options); |
| 10 | + |
| 11 | + if (options && options.readable === false) |
| 12 | + this.readable = false; |
| 13 | + |
| 14 | + if (options && options.writable === false) |
| 15 | + this.writable = false; |
| 16 | +} |
| 17 | + |
| 18 | +util.inherits(DuplexBase, Readable); |
| 19 | + |
| 20 | +{ |
| 21 | + // Avoid scope creep, the keys array can then be collected. |
| 22 | + const keys = Object.keys(Writable.prototype); |
| 23 | + for (var v = 0; v < keys.length; v++) { |
| 24 | + const method = keys[v]; |
| 25 | + if (!DuplexBase.prototype[method]) |
| 26 | + DuplexBase.prototype[method] = Writable.prototype[method]; |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +module.exports = DuplexBase; |
Collapse file
Copy file name to clipboardExpand all lines: node.gyp +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
142 | 142 | 'lib/internal/vm/Module.js', |
143 | 143 | 'lib/internal/streams/lazy_transform.js', |
144 | 144 | 'lib/internal/streams/BufferList.js', |
| 145 | + 'lib/internal/streams/duplex_base.js', |
145 | 146 | 'lib/internal/streams/legacy.js', |
146 | 147 | 'lib/internal/streams/destroy.js', |
147 | 148 | 'lib/internal/wrap_js_stream.js', |
|