mirror of https://github.com/nodejs/node.git
Handle writeStream errors in sys.pump
parent
3e0a8f3ad8
commit
f08985c193
20
lib/sys.js
20
lib/sys.js
|
@ -328,6 +328,15 @@ exports.exec = function () {
|
||||||
|
|
||||||
|
|
||||||
exports.pump = function (readStream, writeStream, callback) {
|
exports.pump = function (readStream, writeStream, callback) {
|
||||||
|
var callbackCalled = false;
|
||||||
|
|
||||||
|
function call (a, b, c) {
|
||||||
|
if (callback && !callbackCalled) {
|
||||||
|
callback(a, b, c);
|
||||||
|
callbackCalled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!readStream.pause) readStream.pause = function () {readStream.emit("pause")};
|
if (!readStream.pause) readStream.pause = function () {readStream.emit("pause")};
|
||||||
if (!readStream.resume) readStream.resume = function () {readStream.emit("resume")};
|
if (!readStream.resume) readStream.resume = function () {readStream.emit("resume")};
|
||||||
|
|
||||||
|
@ -352,12 +361,17 @@ exports.pump = function (readStream, writeStream, callback) {
|
||||||
});
|
});
|
||||||
|
|
||||||
readStream.addListener("close", function () {
|
readStream.addListener("close", function () {
|
||||||
if (callback) callback();
|
call();
|
||||||
});
|
});
|
||||||
|
|
||||||
readStream.addListener("error", function(err) {
|
readStream.addListener("error", function (err) {
|
||||||
writeStream.end();
|
writeStream.end();
|
||||||
if (callback) callback(err);
|
call(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
writeStream.addListener("error", function (err) {
|
||||||
|
readStream.destroy();
|
||||||
|
call(err);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue