mirror of
https://github.com/nodejs/node-v0.x-archive.git
synced 2026-04-28 03:01:10 -04:00
Revert "stream: Writable.end(chunk) after end is an error"
It's breaking ~22 tests, Needs further investigation.
This reverts commit 5222d19a11.
This commit is contained in:
@@ -304,6 +304,10 @@ Writable.prototype._write = function(chunk, cb) {
|
||||
Writable.prototype.end = function(chunk, encoding, cb) {
|
||||
var state = this._writableState;
|
||||
|
||||
// ignore unnecessary end() calls.
|
||||
if (state.ending || state.ended || state.finished)
|
||||
return;
|
||||
|
||||
if (typeof chunk === 'function') {
|
||||
cb = chunk;
|
||||
chunk = null;
|
||||
@@ -313,28 +317,17 @@ Writable.prototype.end = function(chunk, encoding, cb) {
|
||||
encoding = null;
|
||||
}
|
||||
|
||||
if (chunk)
|
||||
this.write(chunk, encoding);
|
||||
|
||||
// ignore unnecessary end() calls.
|
||||
if (!state.ending && !state.ended && !state.finished)
|
||||
endWritable(this, state, !!chunk, cb);
|
||||
};
|
||||
|
||||
function endWritable(stream, state, hadChunk, cb) {
|
||||
state.ending = true;
|
||||
if (!hadChunk &&
|
||||
state.length === 0 &&
|
||||
!state.finishing) {
|
||||
if (chunk)
|
||||
this.write(chunk, encoding, cb);
|
||||
else if (state.length === 0 && !state.finishing && !state.finished) {
|
||||
state.finishing = true;
|
||||
stream.emit('finish');
|
||||
this.emit('finish');
|
||||
state.finished = true;
|
||||
if (cb) process.nextTick(cb);
|
||||
} else if (cb) {
|
||||
this.once('finish', cb);
|
||||
}
|
||||
if (cb) {
|
||||
if (state.finished || state.finishing)
|
||||
process.nextTick(cb);
|
||||
else
|
||||
stream.once('finish', cb);
|
||||
}
|
||||
|
||||
state.ended = true;
|
||||
};
|
||||
|
||||
@@ -311,19 +311,3 @@ test('duplexes are pipable', function(t) {
|
||||
assert(!gotError);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('end(chunk) two times is an error', function(t) {
|
||||
var w = new W();
|
||||
w._write = function() {};
|
||||
var gotError = false;
|
||||
w.on('error', function(er) {
|
||||
gotError = true;
|
||||
t.equal(er.message, 'write after end');
|
||||
});
|
||||
w.end('this is the end');
|
||||
w.end('and so is this');
|
||||
process.nextTick(function() {
|
||||
assert(gotError);
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user