mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
fix(packer) pack: add error handler
This commit is contained in:
parent
7e28316a22
commit
aaf733eeda
1 changed files with 19 additions and 24 deletions
|
|
@ -17,25 +17,28 @@
|
|||
|
||||
exports.pack = function(from, to, callback) {
|
||||
isDir(from, function(is) {
|
||||
var options = {
|
||||
gzip: true
|
||||
};
|
||||
var stream, dir, name,
|
||||
isStr = Util.type.string(to),
|
||||
options = {
|
||||
gzip: true
|
||||
};
|
||||
|
||||
if (!is || !fstream || !tar)
|
||||
if (!is || !fstream || !tar) {
|
||||
pipe(from, to, options, callback);
|
||||
else
|
||||
createTar(from, function(readStream) {
|
||||
var dir, name,
|
||||
isStr = Util.type.string(to);
|
||||
} else {
|
||||
stream = fstream
|
||||
.Reader({ path: from, type: 'Directory' })
|
||||
.on('error', callback)
|
||||
.pipe(tar.Pack({ noProprietary: true }));
|
||||
|
||||
if (isStr) {
|
||||
dir = path.dirname(to);
|
||||
name = path.basename(to);
|
||||
to = dir + path.sep + name + '.tar.gz';
|
||||
}
|
||||
|
||||
pipe(readStream, to, options, callback);
|
||||
});
|
||||
if (isStr) {
|
||||
dir = path.dirname(to);
|
||||
name = path.basename(to);
|
||||
to = dir + path.sep + name + '.tar.gz';
|
||||
}
|
||||
|
||||
pipe(stream, to, options, callback);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -58,14 +61,6 @@
|
|||
pipe(from, write, options, callback);
|
||||
};
|
||||
|
||||
function createTar(from, callback) {
|
||||
var options = { path: from, type: 'Directory' },
|
||||
stream = fstream.Reader(options)
|
||||
.pipe(tar.Pack({ noProprietary: true }));
|
||||
|
||||
callback(stream);
|
||||
}
|
||||
|
||||
function isDir(name, callback) {
|
||||
fs.stat(name, function(error, stat) {
|
||||
var isDir;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue