Skip to content

Commit

Permalink
stream: let Duplex re-use Writable properties
Browse files Browse the repository at this point in the history
Instead of reimplementing Writable properties, fetch them
from the Writable prototype.

PR-URL: #33079
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
ronag authored and addaleax committed Apr 29, 2020
1 parent 766b3c1 commit 5c91a75
Showing 1 changed file with 14 additions and 37 deletions.
51 changes: 14 additions & 37 deletions lib/_stream_duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}
}
});

0 comments on commit 5c91a75

Please sign in to comment.