Skip to content

Commit

Permalink
Adds "pause" and "resume" events to pump and it's readable argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeal authored and ry committed Jul 14, 2010
1 parent 2085909 commit 16cb451
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/sys.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,25 @@ exports.exec = function () {


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();
});
Expand Down

0 comments on commit 16cb451

Please sign in to comment.