diff --git a/headers.js b/headers.js index d4b00dd..8c75edc 100644 --- a/headers.js +++ b/headers.js @@ -164,6 +164,12 @@ exports.encodePax = function (opts) { // TODO: encode more stuff in pax var result = '' if (opts.name) result += addLength(' path=' + opts.name + '\n') if (opts.linkname) result += addLength(' linkpath=' + opts.linkname + '\n') + var pax = opts.pax + if (pax) { + for (var key in pax) { + result += addLength(' ' + key + '=' + pax[key] + '\n') + } + } return new Buffer(result) } diff --git a/pack.js b/pack.js index 45c9a27..2176d15 100644 --- a/pack.js +++ b/pack.js @@ -204,15 +204,21 @@ Pack.prototype.destroy = function (err) { } Pack.prototype._encode = function (header) { - var buf = headers.encode(header) - if (buf) this.push(buf) - else this._encodePax(header) + if (!header.pax) { + var buf = headers.encode(header) + if (buf) { + this.push(buf) + return + } + } + this._encodePax(header) } Pack.prototype._encodePax = function (header) { var paxHeader = headers.encodePax({ name: header.name, - linkname: header.linkname + linkname: header.linkname, + pax: header.pax }) var newHeader = { diff --git a/test/extract.js b/test/extract.js index fe95091..6c95d37 100644 --- a/test/extract.js +++ b/test/extract.js @@ -217,6 +217,43 @@ test('chunked-multi-file', function (t) { extract.end() }) +test('pax', function (t) { + t.plan(3) + + var extract = tar.extract() + var noEntries = false + + extract.on('entry', function (header, stream, callback) { + t.deepEqual(header, { + name: 'pax.txt', + mode: parseInt('644', 8), + uid: 501, + gid: 20, + size: 12, + mtime: new Date(1387580181000), + type: 'file', + linkname: null, + uname: 'maf', + gname: 'staff', + devmajor: 0, + devminor: 0, + pax: { path: 'pax.txt', special: 'sauce' } + }) + + stream.pipe(concat(function (data) { + noEntries = true + t.same(data.toString(), 'hello world\n') + callback() + })) + }) + + extract.on('finish', function () { + t.ok(noEntries) + }) + + extract.end(fs.readFileSync(fixtures.PAX_TAR)) +}) + test('types', function (t) { t.plan(3) diff --git a/test/fixtures/index.js b/test/fixtures/index.js index 0bdf71c..eb18dbd 100644 --- a/test/fixtures/index.js +++ b/test/fixtures/index.js @@ -2,6 +2,7 @@ var path = require('path') exports.ONE_FILE_TAR = path.join(__dirname, 'one-file.tar') exports.MULTI_FILE_TAR = path.join(__dirname, 'multi-file.tar') +exports.PAX_TAR = path.join(__dirname, 'pax.tar') exports.TYPES_TAR = path.join(__dirname, 'types.tar') exports.LONG_NAME_TAR = path.join(__dirname, 'long-name.tar') exports.UNICODE_BSD_TAR = path.join(__dirname, 'unicode-bsd.tar') diff --git a/test/fixtures/pax.tar b/test/fixtures/pax.tar new file mode 100644 index 0000000..f0d9d2f Binary files /dev/null and b/test/fixtures/pax.tar differ diff --git a/test/pack.js b/test/pack.js index 4ceabf2..55817e0 100644 --- a/test/pack.js +++ b/test/pack.js @@ -61,6 +61,31 @@ test('multi-file', function (t) { })) }) +test('pax', function (t) { + t.plan(2) + + var pack = tar.pack() + + pack.entry({ + name: 'pax.txt', + mtime: new Date(1387580181000), + mode: parseInt('644', 8), + uname: 'maf', + gname: 'staff', + uid: 501, + gid: 20, + pax: {special: 'sauce'} + }, 'hello world\n') + + pack.finalize() + + pack.pipe(concat(function (data) { + // fs.writeFileSync('tmp.tar', data) + t.same(data.length & 511, 0) + t.deepEqual(data, fs.readFileSync(fixtures.PAX_TAR)) + })) +}) + test('types', function (t) { t.plan(2) var pack = tar.pack()