mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
Adds "pause" and "resume" events to pump and it's readable argument.
This commit is contained in:
parent
2085909aeb
commit
16cb45103f
1 changed files with 11 additions and 0 deletions
11
lib/sys.js
11
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();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue