From aaf733eedad094242144bb217b9d89620ad0f11d Mon Sep 17 00:00:00 2001 From: coderaiser Date: Sat, 1 Nov 2014 04:19:50 -0400 Subject: [PATCH] fix(packer) pack: add error handler --- lib/server/packer.js | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/lib/server/packer.js b/lib/server/packer.js index 2238a8c0..d003d95b 100644 --- a/lib/server/packer.js +++ b/lib/server/packer.js @@ -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;