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

fixes #5715
This commit is contained in:
Vladimir Kurchatkin 2014-05-06 14:19:54 +04:00 committed by Timothy J Fontaine
parent 1ab98a130e
commit 82fca9136d
2 changed files with 13 additions and 0 deletions

View File

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

View File

@ -391,3 +391,15 @@ test('finish does not come before sync _write cb', function(t) {
}); });
w.end(); 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));
});