tar-pack
Advanced tools
Comparing version 3.1.4 to 3.2.0
11
index.js
@@ -58,3 +58,3 @@ "use strict" | ||
// non-compliant tar implementations. | ||
var tarPack = tar.Pack({ noProprietary: options.noProprietary || false }) | ||
var tarPack = tar.Pack({ noProprietary: options.noProprietary || false, fromBase: options.fromBase || false }) | ||
var gzip = zlib.Gzip() | ||
@@ -96,2 +96,3 @@ | ||
var defaultName = options.defaultName || (options.defaultName === false ? false : 'index.js') | ||
var strip = (options.strip !== undefined) ? options.strip : 1 | ||
@@ -122,4 +123,4 @@ // figure out who we're supposed to be, if we're not pretending | ||
// gzip {tarball} --decompress --stdout \ | ||
// | tar -mvxpf - --strip-components=1 -C {unpackTarget} | ||
gunzTarPerm(tarball, unpackTarget, dMode, fMode, uid, gid, defaultName) | ||
// | tar -mvxpf - --strip-components={strip} -C {unpackTarget} | ||
gunzTarPerm(tarball, unpackTarget, dMode, fMode, uid, gid, defaultName, strip) | ||
} | ||
@@ -130,3 +131,3 @@ return tarball | ||
function gunzTarPerm(tarball, target, dMode, fMode, uid, gid, defaultName) { | ||
function gunzTarPerm(tarball, target, dMode, fMode, uid, gid, defaultName, strip) { | ||
debug('modes %j', [dMode.toString(8), fMode.toString(8)]) | ||
@@ -152,3 +153,3 @@ | ||
var extractOpts = { type: 'Directory', path: target, strip: 1 } | ||
var extractOpts = { type: 'Directory', path: target, strip: strip } | ||
@@ -155,0 +156,0 @@ if (!win32 && typeof uid === 'number' && typeof gid === 'number') { |
{ | ||
"name": "tar-pack", | ||
"version": "3.1.4", | ||
"version": "3.2.0", | ||
"description": "Package and un-package modules of some sort (in tar/gz bundles).", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -28,2 +28,3 @@ # Tar Pack | ||
- `noProprietary` (defaults to `false`) Set this to `true` to prevent any proprietary attributes being added to the tarball. These attributes are allowed by the spec, but may trip up some poorly written tarball parsers. | ||
- `fromBase` (defaults to `false`) Set this to `true` to make sure your tarballs root is the directory you pass in. | ||
- `ignoreFiles` (defaults to `['.gitignore']`) These files can specify files to be excluded from the package using the syntax of `.gitignore`. This option is ignored if you parse a `fstream.DirReader` instead of a string for folder. | ||
@@ -67,2 +68,3 @@ - `filter` (defaults to `entry => true`) A function that takes an entry and returns `true` if it should be included in the package and `false` if it should not. Entryies are of the form `{path, basename, dirname, type}` where (type is "Directory" or "File"). This function is ignored if you parse a `fstream.DirReader` instead of a string for folder. | ||
- `unsafe` - (defaults to `false`) (on non win32 OSes it overrides `gid` and `uid` with the current processes IDs) | ||
- `strip` - (defaults to `1`) Number of path segments to strip from the root when extracting | ||
@@ -83,2 +85,2 @@ Example: | ||
BSD | ||
BSD |
@@ -27,2 +27,12 @@ var tar = require('../') | ||
}) | ||
describe('tarball.pipe(unpack(directory, { strip: 0 }, callback))', function () { | ||
it('unpacks the tarball into the directory with subdir package', function (done) { | ||
read(__dirname + '/fixtures/packed.tar').pipe(tar.unpack(__dirname + '/output/unpacked', { strip: 0 } , function (err) { | ||
if (err) return done(err) | ||
assert.equal(rfile('./output/unpacked/package/bar.txt'), rfile('./fixtures/to-pack/bar.txt')) | ||
assert.equal(rfile('./output/unpacked/package/foo.txt'), rfile('./fixtures/to-pack/foo.txt')) | ||
done() | ||
})) | ||
}) | ||
}) | ||
describe('gziptarball.pipe(unpack(directory, callback))', function () { | ||
@@ -68,2 +78,24 @@ it('unpacks the tarball into the directory', function (done) { | ||
}) | ||
}) | ||
}) | ||
describe('pack(directory, { fromBase: true }).pipe(tarball)', function () { | ||
it('packs the directory with input dir as base dir', function (done) { | ||
var called = false | ||
mkdir(__dirname + '/output/') | ||
tar.pack(__dirname + '/fixtures/to-pack', { fromBase: true }).pipe(write(__dirname + '/output/packed.tar.gz')) | ||
.on('error', function (err) { | ||
if (called) return | ||
called = true | ||
done(err) | ||
}) | ||
.on('close', function () { | ||
if (called) return | ||
called = true | ||
read(__dirname + '/output/packed.tar.gz').pipe(tar.unpack(__dirname + '/output/unpacked', { strip: 0 }, function (err) { | ||
if (err) return done(err) | ||
assert.equal(rfile('./output/unpacked/bar.txt'), rfile('./fixtures/to-pack/bar.txt')) | ||
assert.equal(rfile('./output/unpacked/foo.txt'), rfile('./fixtures/to-pack/foo.txt')) | ||
done() | ||
})) | ||
}) | ||
}) | ||
}) |
21241
308
84