fix(packer) pack: add error handler

This commit is contained in:
coderaiser 2014-11-01 04:19:50 -04:00
parent 7e28316a22
commit aaf733eeda

View file

@ -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;