Browse Source

Adds "pause" and "resume" events to pump and it's readable argument.

v0.7.4-release
Mikeal Rogers 15 years ago
committed by Ryan Dahl
parent
commit
16cb45103f
  1. 11
      lib/sys.js

11
lib/sys.js

@ -284,14 +284,25 @@ exports.exec = function () {
exports.pump = function (readStream, writeStream, callback) { 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) { readStream.addListener("data", function (chunk) {
if (writeStream.write(chunk) === false) readStream.pause(); if (writeStream.write(chunk) === false) readStream.pause();
}); });
writeStream.addListener("pause", function () {
readStream.pause();
});
writeStream.addListener("drain", function () { writeStream.addListener("drain", function () {
readStream.resume(); readStream.resume();
}); });
writeStream.addListener("resume", function () {
readStream.resume();
});
readStream.addListener("end", function () { readStream.addListener("end", function () {
writeStream.end(); writeStream.end();
}); });

Loading…
Cancel
Save