feature(pipe) getBody: add error handling

This commit is contained in:
coderaiser 2014-03-18 07:31:57 -04:00
parent 4eddc74341
commit 1e825698c3

View file

@ -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);
});
}
})();