Skip to content

Commit 6069c26

Browse files
committed
fixup
1 parent fbe7a31 commit 6069c26

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/_stream_writable.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,11 @@ function nop() {}
5959

6060
const kFlush = Symbol('kFlush');
6161
class WritableState extends WritableStateBase {
62-
constructor(options, stream, isDuplex) {
62+
constructor(options, stream) {
6363
super(options);
6464

65+
let isDuplex = options.isDuplex;
66+
6567
// Duplex streams are both readable and writable, but share
6668
// the same options object.
6769
// However, some cases require setting options to different
@@ -207,6 +209,7 @@ function Writable(options) {
207209

208210
WritableBase.call(this, {
209211
...options,
212+
isDuplex,
210213
start: function() {
211214
const state = this._writableState;
212215
if (!state.writing) {
@@ -215,7 +218,8 @@ function Writable(options) {
215218
finishMaybe(this, state);
216219
},
217220
write: writeOrBuffer,
218-
flush: function(state, cb) {
221+
flush: function(cb) {
222+
const state = this._writableState;
219223
// .end() fully uncorks.
220224
if (state.corked) {
221225
state.corked = 1;
@@ -226,7 +230,7 @@ function Writable(options) {
226230

227231
finishMaybe(this, state);
228232
}
229-
}, isDuplex, WritableState);
233+
}, WritableState);
230234
}
231235
Writable.WritableState = WritableState;
232236
Writable.prototype = ObjectCreate(WritableBase.prototype);
@@ -249,7 +253,9 @@ Writable.prototype.uncork = function() {
249253
// If we're already writing something, then just put this
250254
// in the queue, and wait our turn. Otherwise, call _write
251255
// If we return false, then we need a drain event, so set that flag.
252-
function writeOrBuffer(state, chunk, encoding, callback) {
256+
function writeOrBuffer(chunk, encoding, callback) {
257+
const state = this._writableState;
258+
253259
if (typeof callback !== 'function')
254260
callback = nop;
255261

lib/internal/streams/base.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class WritableStateBase {
8585
const kWrite = Symbol('kWrite');
8686
const kFlush = Symbol('kFlush');
8787

88-
function WritableBase(options, isDuplex, State) {
88+
function WritableBase(options, State = WritableStateBase) {
8989
if (typeof options.write !== 'function') {
9090
throw new ERR_INVALID_ARG_TYPE('option.write', 'function', options.write);
9191
}
@@ -98,7 +98,7 @@ function WritableBase(options, isDuplex, State) {
9898
this[kWrite] = options.write;
9999
this[kFlush] = options.flush;
100100

101-
this._writableState = new State(options, this, isDuplex);
101+
this._writableState = new State(options, this);
102102

103103
destroyImpl.construct(this, options.start);
104104
}
@@ -150,7 +150,7 @@ WritableBase.prototype.write = function(chunk, encoding, cb) {
150150
}
151151

152152
// TODO(ronag): Move more logic from Writable into custom cb.
153-
const ret = this[kWrite](state, chunk, encoding, cb);
153+
const ret = this[kWrite](chunk, encoding, cb);
154154
// Return false if errored or destroyed in order to break
155155
// any synchronous while(stream.write(data)) loops.
156156
return ret && !state.errored && !state.destroyed;
@@ -196,7 +196,7 @@ WritableBase.prototype.end = function(chunk, encoding, cb) {
196196
if (!state.errored && !state.ending) {
197197
state.ending = true;
198198
let called = false;
199-
this[kFlush](state, (err) => {
199+
this[kFlush]((err) => {
200200
if (called) {
201201
errorOrDestroy(this, new ERR_MULTIPLE_CALLBACK());
202202
return;

0 commit comments

Comments
 (0)