fix(pipe) create: EventEmitter memory leak

This commit is contained in:
coderaiser 2014-05-29 07:43:29 -04:00
parent 4ea80a38cd
commit f668026771

View file

@ -47,29 +47,37 @@
if (p.gzip || p.gunzip) {
if (p.gzip)
gzip = zlib.createGzip();
gzip = zlib.createGzip();
else
gzip = zlib.createGunzip();
gzip = zlib.createGunzip();
read.on('error', func);
read = read.pipe(gzip);
on('error', read, func);
read = read.pipe(gzip);
}
write.on('error', func);
read.on('error', func);
on('error', write, func);
on('error', read, func);
Util.exec.if(!isFsWrite, function() {
read.pipe(write, {
end: !p.notEnd
});
read.on('end', func);
read.once('end', func);
}, function(callback) {
write.on('open', callback);
on('open', write, callback);
});
}
}
function on(event, emitter, callback) {
var listeners = emitter.listeners(event),
length = listeners.length;
if (length <= 1)
emitter.once(event, callback);
}
/**
* get body of readStream
*
@ -83,11 +91,11 @@
body += chunk;
});
readStream.on('error', function(error) {
readStream.once('error', function(error) {
Util.exec.ret(callback, error);
});
readStream.on('end', function() {
readStream.once('end', function() {
Util.exec(callback, null, body);
});
}