Skip to content

Commit

Permalink
stream: 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.
  • Loading branch information
ronag committed Apr 26, 2020
1 parent ab7d9db commit f5c7fb3
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 f5c7fb3

Please sign in to comment.