feature(rest) add zip

This commit is contained in:
coderaiser 2013-08-02 15:57:04 +00:00
parent e7ba46a9ca
commit 57329e4472

View file

@ -18,6 +18,7 @@
path = main.path,
Util = main.util,
CloudFunc = main.cloudfunc,
zlib = main.zlib,
dir = main.dir,
OK = 200,
Header = main.generateHeaders({
@ -141,7 +142,26 @@
else
main.sendError(pParams, pError);
});
else {
else if (lQuery === 'zip') {
lReadStream = fs.createReadStream(p.name);
lWriteStream = fs.createWriteStream(p.name + '.zip');
lError = function(pError) {
main.sendError(pParams, pError);
};
lWriteStream.on('error', lError);
lReadStream.on('error', lError);
lWriteStream.on('open', function() {
lReadStream.pipe(zlib.createGzip()).pipe(lWriteStream);
//p.request.pipe(process.stdout);
lReadStream.on('end', function() {
var lName = path.basename(p.name) + '.zip';
main.sendResponse(pParams, 'save: ok("' + lName +'")');
});
});
} else {
lWriteStream = fs.createWriteStream(p.name);
lError = function(pError) {