mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(pipe) getBody: add error handling
This commit is contained in:
parent
4eddc74341
commit
1e825698c3
1 changed files with 22 additions and 4 deletions
|
|
@ -12,13 +12,27 @@
|
|||
'# http://cloudcmd.io' + '\n');
|
||||
|
||||
var main = global.cloudcmd.main,
|
||||
Util = main.util,
|
||||
Util = require('util.io'),
|
||||
fs = require('fs'),
|
||||
zlib = require('zlib');
|
||||
|
||||
exports.create = create;
|
||||
exports.getBody = getBody;
|
||||
|
||||
exports.create = function(params) {
|
||||
/**
|
||||
* create pipe
|
||||
* params: {callback, read or from, write or to, gzip}
|
||||
* read - readable stream
|
||||
* write - writable stream
|
||||
* to - name of file to write
|
||||
* from - name of file to read
|
||||
* gzip - should gzip to be used
|
||||
* callback - function(error) {}
|
||||
*
|
||||
* @param params
|
||||
* @param callback
|
||||
*/
|
||||
function create(params) {
|
||||
var gzip, onError, read, write, isFsWrite,
|
||||
p = params;
|
||||
|
||||
|
|
@ -62,7 +76,7 @@
|
|||
write.on('open', callback);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* get body of readStream
|
||||
|
|
@ -77,8 +91,12 @@
|
|||
body += chunk;
|
||||
});
|
||||
|
||||
readStream.on('error', function(error) {
|
||||
Util.retExec(callback, error);
|
||||
});
|
||||
|
||||
readStream.on('end', function() {
|
||||
Util.exec(callback, body);
|
||||
Util.exec(callback, null, body);
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue