From f5c7fb3c2d21fb262fc4c263175737b8e12a9b4d Mon Sep 17 00:00:00 2001 From: Robert Nagy Date: Sun, 26 Apr 2020 19:38:43 +0200 Subject: [PATCH] stream: Duplex re-use Writable properties Instead of reimplementing Writable properties, fetch them from the Writable prototype. --- lib/_stream_duplex.js | 51 ++++++++++++------------------------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js index 07a16175ffcd73..ced361c8d60898 100644 --- a/lib/_stream_duplex.js +++ b/lib/_stream_duplex.js @@ -71,7 +71,20 @@ function Duplex(options) { } ObjectDefineProperties(Duplex.prototype, { - writable: ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writable'), + writable: + ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writable'), + writableHighWaterMark: + ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableHighWaterMark'), + writableBuffer: + ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableBuffer'), + writableLength: + ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableLength'), + writableFinished: + ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableFinished'), + writableCorked: + ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableCorked'), + writableEnded: + ObjectGetOwnPropertyDescriptor(Writable.prototype, 'writableEnded'), destroyed: { get() { @@ -89,41 +102,5 @@ ObjectDefineProperties(Duplex.prototype, { this._writableState.destroyed = value; } } - }, - - writableHighWaterMark: { - get() { - return this._writableState && this._writableState.highWaterMark; - } - }, - - writableBuffer: { - get() { - return this._writableState && this._writableState.getBuffer(); - } - }, - - writableLength: { - get() { - return this._writableState && this._writableState.length; - } - }, - - writableFinished: { - get() { - return this._writableState ? this._writableState.finished : false; - } - }, - - writableCorked: { - get() { - return this._writableState ? this._writableState.corked : 0; - } - }, - - writableEnded: { - get() { - return this._writableState ? this._writableState.ending : false; - } } });