pack should respect header.pax like extract
This commit is contained in:
parent
7ce8960772
commit
c60b9a71ec
6 changed files with 79 additions and 4 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
12
pack.js
12
pack.js
|
@ -204,15 +204,21 @@ Pack.prototype.destroy = function (err) {
|
|||
}
|
||||
|
||||
Pack.prototype._encode = function (header) {
|
||||
if (!header.pax) {
|
||||
var buf = headers.encode(header)
|
||||
if (buf) this.push(buf)
|
||||
else this._encodePax(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 = {
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
1
test/fixtures/index.js
vendored
1
test/fixtures/index.js
vendored
|
@ -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')
|
||||
|
|
BIN
test/fixtures/pax.tar
vendored
Normal file
BIN
test/fixtures/pax.tar
vendored
Normal file
Binary file not shown.
25
test/pack.js
25
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()
|
||||
|
|
Loading…
Reference in a new issue