mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-24 03:05:41 +00:00
refactor(rest) put cp: add putFile
This commit is contained in:
parent
7d9e360a83
commit
8bbda264cf
1 changed files with 16 additions and 23 deletions
|
|
@ -329,24 +329,17 @@
|
|||
break;
|
||||
|
||||
case 'cp':
|
||||
if (Util.checkObjTrue(lFiles, ['from', 'to'])) {
|
||||
var l = lFiles,
|
||||
lReadStream = fs.createReadStream(l.from),
|
||||
lWriteStream = fs.createWriteStream(l.to),
|
||||
|
||||
lError = function(pError){
|
||||
main.sendError(pParams, pError);
|
||||
};
|
||||
|
||||
lWriteStream.on('error', lError);
|
||||
lReadStream.on('error', lError);
|
||||
|
||||
lReadStream.on('end', function(){
|
||||
sendMsg(pParams, 'copy', l.to);
|
||||
});
|
||||
|
||||
lReadStream.pipe(lWriteStream);
|
||||
}
|
||||
if (Util.checkObjTrue(lFiles, ['from', 'to']))
|
||||
putFile({
|
||||
from : lFiles.from,
|
||||
to : lFiles.to,
|
||||
callback : function(pError) {
|
||||
if (pError)
|
||||
main.sendError(pParams, pError);
|
||||
else
|
||||
sendMsg(pParams, 'copy', lFiles.to);
|
||||
}
|
||||
});
|
||||
else
|
||||
main.sendError(pParams, p.data);
|
||||
break;
|
||||
|
|
@ -392,17 +385,17 @@
|
|||
|
||||
if (p.zip) {
|
||||
lZlib = zlib.createGzip();
|
||||
p.read.on('error', lError);
|
||||
p.read = p.read.pipe(lZlib);
|
||||
lRead.on('error', lError);
|
||||
lRead = lRead.pipe(lZlib);
|
||||
}
|
||||
|
||||
lWrite.on('error', lError);
|
||||
p.read.on('error', lError);
|
||||
lRead.on('error', lError);
|
||||
|
||||
lWrite.on('open', function() {
|
||||
p.read.pipe(lWrite);
|
||||
lRead.pipe(lWrite);
|
||||
|
||||
p.read.on('end', function() {
|
||||
lRead.on('end', function() {
|
||||
Util.exec(p.callback);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue