| 62 | Duplex.prototype.destroy = Writable.prototype.destroy; |
| 63 | |
| 64 | function Duplex(options) { |
| 65 | if (!(this instanceof Duplex)) |
| 66 | return new Duplex(options); |
| 67 | |
| 68 | this._events ??= { |
| 69 | close: undefined, |
| 70 | error: undefined, |
| 71 | prefinish: undefined, |
| 72 | finish: undefined, |
| 73 | drain: undefined, |
| 74 | data: undefined, |
| 75 | end: undefined, |
| 76 | readable: undefined, |
| 77 | // Skip uncommon events... |
| 78 | // pause: undefined, |
| 79 | // resume: undefined, |
| 80 | // pipe: undefined, |
| 81 | // unpipe: undefined, |
| 82 | // [destroyImpl.kConstruct]: undefined, |
| 83 | // [destroyImpl.kDestroy]: undefined, |
| 84 | }; |
| 85 | |
| 86 | this._readableState = new Readable.ReadableState(options, this, true); |
| 87 | this._writableState = new Writable.WritableState(options, this, true); |
| 88 | |
| 89 | if (options) { |
| 90 | this.allowHalfOpen = options.allowHalfOpen !== false; |
| 91 | |
| 92 | if (options.readable === false) { |
| 93 | this._readableState.readable = false; |
| 94 | this._readableState.ended = true; |
| 95 | this._readableState.endEmitted = true; |
| 96 | } |
| 97 | |
| 98 | if (options.writable === false) { |
| 99 | this._writableState.writable = false; |
| 100 | this._writableState.ending = true; |
| 101 | this._writableState.ended = true; |
| 102 | this._writableState.finished = true; |
| 103 | } |
| 104 | |
| 105 | if (typeof options.read === 'function') |
| 106 | this._read = options.read; |
| 107 | |
| 108 | if (typeof options.write === 'function') |
| 109 | this._write = options.write; |
| 110 | |
| 111 | if (typeof options.writev === 'function') |
| 112 | this._writev = options.writev; |
| 113 | |
| 114 | if (typeof options.destroy === 'function') |
| 115 | this._destroy = options.destroy; |
| 116 | |
| 117 | if (typeof options.final === 'function') |
| 118 | this._final = options.final; |
| 119 | |
| 120 | if (typeof options.construct === 'function') |
| 121 | this._construct = options.construct; |