From 16cb45103f29a46fbd19eb19e3042678800e1b70 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Tue, 13 Jul 2010 17:17:05 -0700 Subject: [PATCH] Adds "pause" and "resume" events to pump and it's readable argument. --- lib/sys.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/sys.js b/lib/sys.js index ac8b023c4b..867b5a9e01 100644 --- a/lib/sys.js +++ b/lib/sys.js @@ -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(); });