Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

stream: Writable.end(chunk) after end is an error

Calling end(data) calls write(data).  Doing this after end should
raise a 'write after end' error.

However, because end() calls were previously ignored on already
ended streams, this error was confusingly suppressed, even though the
data never is written, and cannot get to the other side.

This is a re-hash of 5222d19, but
without assuming that the data passed to end() is valid, and thus
breaking a bunch of tests.
  • Loading branch information...
commit 33356eb97632d1bbf381e240f541ebae64cee248 1 parent f5d8496
Isaac Z. Schlueter authored

Showing 1 changed file with 5 additions and 7 deletions. Show diff stats Hide diff stats

  1. +5 7 lib/_stream_writable.js
12 lib/_stream_writable.js
@@ -313,19 +313,17 @@ Writable.prototype.end = function(chunk, encoding, cb) {
313 313 encoding = null;
314 314 }
315 315
316   - if (chunk)
  316 + if (typeof chunk !== 'undefined' && chunk !== null)
317 317 this.write(chunk, encoding);
318 318
319 319 // ignore unnecessary end() calls.
320 320 if (!state.ending && !state.ended && !state.finished)
321   - endWritable(this, state, !!chunk, cb);
  321 + endWritable(this, state, cb);
322 322 };
323 323
324   -function endWritable(stream, state, hadChunk, cb) {
  324 +function endWritable(stream, state, cb) {
325 325 state.ending = true;
326   - if (!hadChunk &&
327   - state.length === 0 &&
328   - !state.finishing) {
  326 + if (state.length === 0 && !state.finishing) {
329 327 state.finishing = true;
330 328 stream.emit('finish');
331 329 state.finished = true;
@@ -337,4 +335,4 @@ function endWritable(stream, state, hadChunk, cb) {
337 335 stream.once('finish', cb);
338 336 }
339 337 state.ended = true;
340   -};
  338 +}

0 comments on commit 33356eb

Please sign in to comment.
Something went wrong with that request. Please try again.