pack should respect header.pax like extract

This commit is contained in:
Bradley Farias 2016-04-05 09:40:00 -05:00
parent 7ce8960772
commit c60b9a71ec
6 changed files with 79 additions and 4 deletions

View file

@ -164,6 +164,12 @@ exports.encodePax = function (opts) { // TODO: encode more stuff in pax
var result = '' var result = ''
if (opts.name) result += addLength(' path=' + opts.name + '\n') if (opts.name) result += addLength(' path=' + opts.name + '\n')
if (opts.linkname) result += addLength(' linkpath=' + opts.linkname + '\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) return new Buffer(result)
} }

12
pack.js
View file

@ -204,15 +204,21 @@ Pack.prototype.destroy = function (err) {
} }
Pack.prototype._encode = function (header) { Pack.prototype._encode = function (header) {
if (!header.pax) {
var buf = headers.encode(header) var buf = headers.encode(header)
if (buf) this.push(buf) if (buf) {
else this._encodePax(header) this.push(buf)
return
}
}
this._encodePax(header)
} }
Pack.prototype._encodePax = function (header) { Pack.prototype._encodePax = function (header) {
var paxHeader = headers.encodePax({ var paxHeader = headers.encodePax({
name: header.name, name: header.name,
linkname: header.linkname linkname: header.linkname,
pax: header.pax
}) })
var newHeader = { var newHeader = {

View file

@ -217,6 +217,43 @@ test('chunked-multi-file', function (t) {
extract.end() 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) { test('types', function (t) {
t.plan(3) t.plan(3)

View file

@ -2,6 +2,7 @@ var path = require('path')
exports.ONE_FILE_TAR = path.join(__dirname, 'one-file.tar') exports.ONE_FILE_TAR = path.join(__dirname, 'one-file.tar')
exports.MULTI_FILE_TAR = path.join(__dirname, 'multi-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.TYPES_TAR = path.join(__dirname, 'types.tar')
exports.LONG_NAME_TAR = path.join(__dirname, 'long-name.tar') exports.LONG_NAME_TAR = path.join(__dirname, 'long-name.tar')
exports.UNICODE_BSD_TAR = path.join(__dirname, 'unicode-bsd.tar') exports.UNICODE_BSD_TAR = path.join(__dirname, 'unicode-bsd.tar')

BIN
test/fixtures/pax.tar vendored Normal file

Binary file not shown.

View file

@ -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) { test('types', function (t) {
t.plan(2) t.plan(2)
var pack = tar.pack() var pack = tar.pack()