From c60b9a71ec8442bb17e243ae4511287c35d2575b Mon Sep 17 00:00:00 2001 From: Bradley Farias Date: Tue, 5 Apr 2016 09:40:00 -0500 Subject: [PATCH] pack should respect header.pax like extract --- headers.js | 6 ++++++ pack.js | 14 ++++++++++---- test/extract.js | 37 +++++++++++++++++++++++++++++++++++++ test/fixtures/index.js | 1 + test/fixtures/pax.tar | Bin 0 -> 3072 bytes test/pack.js | 25 +++++++++++++++++++++++++ 6 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/pax.tar 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 0000000000000000000000000000000000000000..f0d9d2f11038c430218f9124532b049e6d73c6c2 GIT binary patch literal 3072 zcmeHGK?;K~5cKRT_621Vvhn1-N58OW#6pUqk>>eb>Om-_pdeJ5y=<~fmYE?_alATi z+?X9#h-i(0OnPDI)ln~Z8A%xhN^2rz$Y=so+FFDx9!F{2JWqi~p?2qX9ey|oto?>q zlq}*<$e*N?g@Hp?4jeBbhFlde4X(biFDIUBm!CvOqPfq3>KF2_%zOTcBtp1P(zaKB cp8w8y-@~IHeUqZT?dK$Pav(X795}TDPs$@ZE&u=k literal 0 HcmV?d00001 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()