Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2010-08-25 13:59:18 +0400
committerisaacs <i@izs.me>2010-08-25 16:21:53 +0400
commit6cb1f9c920db802f4009130748d444fb5c3dbb45 (patch)
tree506ceca12d4537a13a19fee068f90e665854fb80
parenta9a05c5d6c8987d9192b9f7f755d8f48db709eaf (diff)
Split the tar and gzipping apart from one another, for portable win
-rw-r--r--lib/cache.js33
1 files changed, 27 insertions, 6 deletions
diff --git a/lib/cache.js b/lib/cache.js
index d4ab174db..8ff20e913 100644
--- a/lib/cache.js
+++ b/lib/cache.js
@@ -5,6 +5,8 @@ exports.unpack = unpack
var mkdir = require("./utils/mkdir-p")
, exec = require("./utils/exec")
+ , pipe = exec.pipe
+ , spawn = exec.spawn
, fetch = require("./utils/fetch")
, npm = require("../npm")
, fs = require("./utils/graceful-fs")
@@ -13,6 +15,7 @@ var mkdir = require("./utils/mkdir-p")
, registry = require("./utils/registry")
, log = require("./utils/log")
, path = require("path")
+ , sys = require("sys")
function cache (args, cb) {
var cmd = args.shift()
@@ -203,7 +206,12 @@ function unpack (pkg, ver, unpackTarget, cb) {
function unpackTar (tarball, unpackTarget, cb) {
mkdir(unpackTarget, function (er) {
if (er) return log.er(cb, "Could not create "+unpackTarget)(er)
- exec("tar", ["xzf", tarball, "--strip-components=1", "-C", unpackTarget], cb)
+ // cp the gzip of the tarball, pipe the stdout into tar's stdin
+ // gzip {tarball} --decompress --stdout | tar xf - --strip-components=1 -C {unpackTarget}
+ pipe( spawn("gzip", ["--decompress", "--stdout", tarball])
+ , spawn("tar", ["vxf", "-", "--strip-components=1", "-C", unpackTarget])
+ , cb
+ )
})
}
function packTar (targetTarball, folder, cb) {
@@ -224,12 +232,25 @@ function packTar (targetTarball, folder, cb) {
mkdir(path.dirname(targetTarball), function (er) {
if (er) return log.er(cb, "Could not create "+targetTarball)(er)
process.chdir(parent)
- var args = [ "czf", targetTarball, "--exclude", ".git" ]
- args = args.concat(["-X", ignore])
- if (include) args = args.concat(["-T", include])
+ // tar xf - --strip-components=1 -C {unpackTarget} | gzip {tarball} > targetTarball
+ var target = fs.createWriteStream(targetTarball)
+ , unPacked = false
+ , args = [ "cv", "--exclude", ".git", "-X", ignore]
+ if (include) args.push("-T", include)
args.push(addFolder)
- exec( "tar", args, cb )
- process.chdir(cwd)
+ var tar = spawn("tar", args)
+ , gzip = spawn("gzip", ["--stdout"])
+ , errState
+ pipe(tar, gzip, function (er) {
+ if (errState) return
+ if (er) return cb(errState = er)
+ })
+ sys.pump(gzip.stdout, target, function (er, ok) {
+ if (errState) return
+ if (er) return cb(errState = er)
+ process.chdir(cwd)
+ cb()
+ })
})
})
})