mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
refactor(pipe) onError -> func
This commit is contained in:
parent
176f87205e
commit
df1443ea47
1 changed files with 7 additions and 10 deletions
|
|
@ -33,8 +33,9 @@
|
|||
* @param callback
|
||||
*/
|
||||
function create(params) {
|
||||
var gzip, onError, read, write, isFsWrite,
|
||||
p = params;
|
||||
var gzip, read, write, isFsWrite,
|
||||
p = params,
|
||||
func = Util.retExec(p.callback);
|
||||
|
||||
if (p) {
|
||||
read = p.read || fs.createReadStream(p.from, {
|
||||
|
|
@ -48,22 +49,18 @@
|
|||
isFsWrite = true;
|
||||
}
|
||||
|
||||
onError = function(error) {
|
||||
Util.exec(p.callback, error);
|
||||
};
|
||||
|
||||
if (p.gzip || p.gunzip) {
|
||||
if (p.gzip)
|
||||
gzip = zlib.createGzip();
|
||||
else
|
||||
gzip = zlib.createGunzip();
|
||||
|
||||
read.on('error', onError);
|
||||
read.on('error', func);
|
||||
read = read.pipe(gzip);
|
||||
}
|
||||
|
||||
write.on('error', onError);
|
||||
read.on('error', onError);
|
||||
write.on('error', func);
|
||||
read.on('error', func);
|
||||
|
||||
Util.ifExec(!isFsWrite, function() {
|
||||
read.on('data', function(data) {
|
||||
|
|
@ -74,7 +71,7 @@
|
|||
if (!p.notEnd)
|
||||
write.end();
|
||||
|
||||
Util.exec(p.callback);
|
||||
func();
|
||||
});
|
||||
}, function(callback) {
|
||||
write.on('open', callback);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue