mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
fix(pipe) create: EventEmitter memory leak
This commit is contained in:
parent
4ea80a38cd
commit
f668026771
1 changed files with 18 additions and 10 deletions
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue