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