Remove resume and pause events

Too complex; unnecessary.
This commit is contained in:
Ryan Dahl 2011-10-24 11:55:02 -07:00
Родитель 4c5751ba97
Коммит 239b3d62de
3 изменённых файлов: 6 добавлений и 50 удалений

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

@ -93,9 +93,6 @@ This keeps `process.stdout` open so that "Goodbye" can be written at the end.
process.stdout.write("Goodbye\n");
});
NOTE: If the source stream does not support `pause()` and `resume()`, this function
adds simple definitions which simply emit `'pause'` and `'resume'` events on
the source stream.
## Writable Stream

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

@ -33,14 +33,18 @@ Stream.prototype.pipe = function(dest, options) {
function ondata(chunk) {
if (dest.writable) {
if (false === dest.write(chunk)) source.pause();
if (false === dest.write(chunk) && source.pause) {
source.pause();
}
}
}
source.on('data', ondata);
function ondrain() {
if (source.readable) source.resume();
if (source.readable && source.resume) {
source.resume();
}
}
dest.on('drain', ondrain);
@ -103,32 +107,6 @@ Stream.prototype.pipe = function(dest, options) {
source.on('error', onerror);
dest.on('error', onerror);
// guarantee that source streams can be paused and resumed, even
// if the only effect is to proxy the event back up the pipe chain.
if (!source.pause) {
source.pause = function() {
source.emit('pause');
};
}
if (!source.resume) {
source.resume = function() {
source.emit('resume');
};
}
function onpause() {
source.pause();
}
dest.on('pause', onpause);
function onresume() {
if (source.readable) source.resume();
}
dest.on('resume', onresume);
// remove all the event listeners that were added.
function cleanup() {
source.removeListener('data', ondata);
@ -137,9 +115,6 @@ Stream.prototype.pipe = function(dest, options) {
source.removeListener('end', onend);
source.removeListener('close', onclose);
dest.removeListener('pause', onpause);
dest.removeListener('resume', onresume);
source.removeListener('error', onerror);
dest.removeListener('error', onerror);

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

@ -466,30 +466,14 @@ exports.pump = function(readStream, writeStream, callback) {
}
}
if (!readStream.pause) {
readStream.pause = function() {readStream.emit('pause');};
}
if (!readStream.resume) {
readStream.resume = function() {readStream.emit('resume');};
}
readStream.addListener('data', function(chunk) {
if (writeStream.write(chunk) === false) readStream.pause();
});
writeStream.addListener('pause', function() {
readStream.pause();
});
writeStream.addListener('drain', function() {
readStream.resume();
});
writeStream.addListener('resume', function() {
readStream.resume();
});
readStream.addListener('end', function() {
writeStream.end();
});