streams2: Unpipe on dest.emit('close')

This commit is contained in:
isaacs 2012-11-28 22:09:28 -08:00
Родитель 49ea653363
Коммит d58f2654bc
1 изменённых файлов: 12 добавлений и 1 удалений

Просмотреть файл

@ -350,11 +350,22 @@ Readable.prototype.pipe = function(dest, pipeOpts) {
// if the dest has an error, then stop piping into it.
// however, don't suppress the throwing behavior for this.
dest.once('error', function(er) {
src.unpipe(dest);
unpipe();
if (dest.listeners('error').length === 0)
dest.emit('error', er);
});
// if the dest emits close, then presumably there's no point writing
// to it any more.
dest.on('close', unpipe);
dest.on('finish', function() {
dest.removeListener('close', unpipe);
});
function unpipe() {
src.unpipe(dest);
}
// tell the dest that it's being piped to
dest.emit('pipe', src);