You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2013/06/12 19:16:09 UTC

[53/56] [abbrv] git commit: axed tar.gz in favour of isaacs tar module. first pass the .gz into zlib, then the .tar into tar, and stuff works out.

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/c23c8472
Tree: http://git-wip-us.apache.org/repos/asf/cordova-cli/tree/c23c8472
Diff: http://git-wip-us.apache.org/repos/asf/cordova-cli/diff/c23c8472

Branch: refs/heads/lazy
Commit: c23c84725e877a0718269fc1aca6cb5682cbfab7
Parents: b4cb5d1
Author: Fil Maj <ma...@gmail.com>
Authored: Mon Jun 10 22:36:46 2013 -0700
Committer: Fil Maj <ma...@gmail.com>
Committed: Wed Jun 12 10:14:53 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/c23c8472/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 3298dd3..5ed2492 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/c23c8472/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) {