Browse files

extra hack to unregister cleanup listeners when piped to

  • Loading branch information...
1 parent ce61cb8 commit 1c2f96153818b46bae38a50c967a383bb93ccd40 @substack committed Sep 22, 2012
Showing with 14 additions and 2 deletions.
  1. +11 −1 index.js
  2. +1 −1 package.json
  3. +2 −0 readme.markdown
View
12 index.js
@@ -23,7 +23,17 @@ var events = require('events');
var util = require('util');
function Stream() {
- events.EventEmitter.call(this);
+ var self = this;
+ events.EventEmitter.call(self);
+
+ self.on('pipe', function (src) {
+ // hack to remove the cleanup handler on 'end' from the core pipe() implementation
+ var fns = self.listeners('end');
+ var fn = fns[fns.length - 1];
+ if (fn.name === 'cleanup') {
+ self.removeListener('end', fn);
+ }
+ });
}
util.inherits(Stream, events.EventEmitter);
module.exports = Stream;
View
2 package.json
@@ -1,6 +1,6 @@
{
"name" : "duplex-pipe",
- "version" : "0.0.0",
+ "version" : "0.0.1",
"description" : "a friendlier .pipe() for duplex streams that doesn't do cleanup on 'end'",
"main" : "index.js",
"dependencies" : {},
View
2 readme.markdown
@@ -9,6 +9,8 @@ per
This is exactly the same as node 0.8 core Stream except that duplex-pipe will
not do `dest.on('end', cleanup)` if `dest` is readable.
+Plus there is another hack to remove cleanup listeners when piped to.
+
# install
With [npm](https://npmjs.org) do:

0 comments on commit 1c2f961

Please sign in to comment.