diff options
author | Ryan Dahl <ry@tinyclouds.org> | 2010-11-20 23:08:45 -0800 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2010-11-20 23:08:45 -0800 |
commit | c321e9893d9eabefb125d9e4efa964603fed9dfe (patch) | |
tree | f19a2b45bfb2993e45765e7de35b14d86e65fa89 /lib/stream.js | |
parent | 23204979926a3f69144be182786c5d2dcf58c0c2 (diff) | |
download | android-node-v8-c321e9893d9eabefb125d9e4efa964603fed9dfe.tar.gz android-node-v8-c321e9893d9eabefb125d9e4efa964603fed9dfe.tar.bz2 android-node-v8-c321e9893d9eabefb125d9e4efa964603fed9dfe.zip |
stream.pipe should remove listeners on dest close
Diffstat (limited to 'lib/stream.js')
-rw-r--r-- | lib/stream.js | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/lib/stream.js b/lib/stream.js index 97f4fa6022..dfe5380adf 100644 --- a/lib/stream.js +++ b/lib/stream.js @@ -10,13 +10,17 @@ exports.Stream = Stream; Stream.prototype.pipe = function (dest, options) { var source = this; - source.on("data", function (chunk) { + function ondata (chunk) { if (false === dest.write(chunk)) source.pause(); - }); + } + + source.on("data", ondata); - dest.on("drain", function () { + function ondrain () { if (source.readable) source.resume(); - }); + } + + dest.on("drain", ondrain); /* * If the 'end' option is not supplied, dest.end() will be called when @@ -24,11 +28,20 @@ Stream.prototype.pipe = function (dest, options) { */ if (!options || options.end !== false) { - source.on("end", function () { + function onend () { dest.end(); - }); + } + + source.on("end", onend); } + dest.on('close', function () { + dest.removeListener('data', ondata); + dest.removeListener('drain', ondrain); + dest.removeListener('end', onend); + }); + + /* * Questionable: */ |