Browse Source

stream: don't try to finish if buffer is not empty

fixes #5715
archived-io.js-v0.10
Vladimir Kurchatkin 11 years ago
committed by Timothy J Fontaine
parent
commit
82fca9136d
  1. 1
      lib/_stream_writable.js
  2. 12
      test/simple/test-stream2-writable.js

1
lib/_stream_writable.js

@ -426,6 +426,7 @@ Writable.prototype.end = function(chunk, encoding, cb) {
function needFinish(stream, state) {
return (state.ending &&
state.length === 0 &&
state.buffer.length === 0 &&
!state.finished &&
!state.writing);
}

12
test/simple/test-stream2-writable.js

@ -391,3 +391,15 @@ test('finish does not come before sync _write cb', function(t) {
});
w.end();
});
test('finish is emitted if last chunk is empty', function(t) {
var w = new W();
w._write = function(chunk, e, cb) {
process.nextTick(cb);
};
w.on('finish', function() {
t.end();
});
w.write(Buffer(1));
w.end(Buffer(0));
});

Loading…
Cancel
Save