axed tar.gz in favour of isaacs tar module. first pass the .gz into zlib, then the .tar into tar, and stuff works out.
Project: http://git-wip-us.apache.org/repos/asf/cordova-cli/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-cli/commit/a42ee2e0 Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/a42ee2e0 Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/a42ee2e0 Branch: refs/heads/master2 Commit: a42ee2e0d7ab6b23351987debba7eb28bec027af Parents: 944c2e4 Author: Fil Maj <[email protected]> Authored: Mon Jun 10 22:36:46 2013 -0700 Committer: Fil Maj <[email protected]> Committed: Thu Jun 13 11:13:20 2013 -0700 ---------------------------------------------------------------------- package.json | 2 +- src/lazy_load.js | 56 ++++++++++++++++++++++++++++++++------------------- 2 files changed, 36 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a42ee2e0/package.json ---------------------------------------------------------------------- diff --git a/package.json b/package.json index 587cb3b..95baffb 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "glob":"3.2.x", "follow-redirects":"0.0.x", "prompt":"0.2.7", - "tar.gz":"0.1.x", + "tar":"0.1.x", "ripple-emulator":">=0.9.15", "open": "0.0.3" }, http://git-wip-us.apache.org/repos/asf/cordova-cli/blob/a42ee2e0/src/lazy_load.js ---------------------------------------------------------------------- diff --git a/src/lazy_load.js b/src/lazy_load.js index 688e101..8094965 100644 --- a/src/lazy_load.js +++ b/src/lazy_load.js @@ -23,7 +23,8 @@ var path = require('path'), events = require('./events'), glob = require('glob'), https = require('follow-redirects').https, - targz = require('tar.gz'), + zlib = require('zlib'), + tar = require('tar'), util = require('./util'); /** @@ -61,28 +62,41 @@ module.exports = function lazy_load(platform, callback) { // TODO: hook in end event downloadfile.end(); events.emit('log', 'Download complete. Extracting...'); - - new targz().extract(filename, util.libDirectory, function(err) { - if (err) { - if (callback) return callback(err); - else throw err; - } else { - // rename the extracted dir to remove the trailing SHA - glob(path.join(util.libDirectory, 'cordova-' + platform + '-' + util.cordovaTag + '-*'), function(err, entries) { - if (err) { - if (callback) return callback(err); - else throw err; - } else { - var entry = entries[0]; - var final_dir = path.join(util.libDirectory, 'cordova-' + platform + '-' + util.cordovaTag); - shell.mkdir(final_dir); - shell.mv('-f', path.join(entry, (platform=='blackberry'?'blackberry10':''), '*'), final_dir); - shell.rm('-rf', entry); - if (callback) callback(); - } + var tar_path = path.join(util.libDirectory, 'cordova-' + platform + '-' + util.cordovaTag + '.tar'); + var tarfile = fs.createWriteStream(tar_path); + tarfile.on('error', function(err) { + if (callback) callback(err); + else throw err; + }); + tarfile.on('finish', function() { + shell.rm(filename); + fs.createReadStream(tar_path) + .pipe(tar.Extract({ path: util.libDirectory })) + .on("error", function (err) { + if (callback) callback(err); + else throw err; + }) + .on("end", function () { + shell.rm(tar_path); + // rename the extracted dir to remove the trailing SHA + glob(path.join(util.libDirectory, 'cordova-' + platform + '-' + util.cordovaTag + '-*'), function(err, entries) { + if (err) { + if (callback) return callback(err); + else throw err; + } else { + var entry = entries[0]; + var final_dir = path.join(util.libDirectory, 'cordova-' + platform + '-' + util.cordovaTag); + shell.mkdir(final_dir); + shell.mv('-f', path.join(entry, (platform=='blackberry'?'blackberry10':''), '*'), final_dir); + shell.rm('-rf', entry); + if (callback) callback(); + } + }); }); - } }); + fs.createReadStream(filename) + .pipe(zlib.createUnzip()) + .pipe(tarfile); }); }); req.on('error', function(err) {
