Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a contentsByteOffset to the header emitted on entry events. #170

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,9 @@ class Extract extends Writable {

this._stream = this._createStream()
this._missing = this._header.size
const header = { ...this._header, contentsByteOffset: this._buffer.shifted }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can name it byteOffset just, similar to how that property is normally used.

in headers.decode, just declare it there and init it to 0, then simply mutate it in here instead of the spread

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've applied these changes. Thank you! 🙏


this.emit('entry', this._header, this._stream, this._unlockBound)
this.emit('entry', header, this._stream, this._unlockBound)
return true
}

Expand Down
48 changes: 32 additions & 16 deletions test/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ test('one-file', function (t) {
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 512
})

stream.pipe(concat(function (data) {
Expand Down Expand Up @@ -61,7 +62,8 @@ test('chunked-one-file', function (t) {
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 512
})

stream.pipe(concat(function (data) {
Expand Down Expand Up @@ -111,7 +113,8 @@ test('multi-file', function (t) {
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 512
})

extract.on('entry', onfile2)
Expand All @@ -135,7 +138,8 @@ test('multi-file', function (t) {
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 1536
})

stream.pipe(concat(function (data) {
Expand Down Expand Up @@ -178,7 +182,8 @@ test('chunked-multi-file', function (t) {
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 512
})

extract.on('entry', onfile2)
Expand All @@ -202,7 +207,8 @@ test('chunked-multi-file', function (t) {
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 1536
})

stream.pipe(concat(function (data) {
Expand Down Expand Up @@ -233,7 +239,8 @@ test('pax', function (t) {
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: { path: 'pax.txt', special: 'sauce' }
pax: { path: 'pax.txt', special: 'sauce' },
contentsByteOffset: 1536
})

stream.pipe(concat(function (data) {
Expand Down Expand Up @@ -337,7 +344,8 @@ test('long-name', function (t) {
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 512
})

stream.pipe(concat(function (data) {
Expand Down Expand Up @@ -374,7 +382,8 @@ test('unicode-bsd', function (t) { // can unpack a bsdtar unicoded tarball
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: { 'SCHILY.dev': '16777217', 'SCHILY.ino': '3599143', 'SCHILY.nlink': '1', atime: '1387589077', ctime: '1387588646', path: 'høllø.txt' }
pax: { 'SCHILY.dev': '16777217', 'SCHILY.ino': '3599143', 'SCHILY.nlink': '1', atime: '1387589077', ctime: '1387588646', path: 'høllø.txt' },
contentsByteOffset: 1536
})

stream.pipe(concat(function (data) {
Expand Down Expand Up @@ -411,7 +420,8 @@ test('unicode', function (t) { // can unpack a bsdtar unicoded tarball
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: { path: 'høstål.txt' }
pax: { path: 'høstål.txt' },
contentsByteOffset: 1536
})

stream.pipe(concat(function (data) {
Expand Down Expand Up @@ -528,7 +538,8 @@ test('base 256 size', function (t) {
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 512
})
cb()
})
Expand Down Expand Up @@ -561,7 +572,8 @@ test('latin-1', function (t) { // can unpack filenames encoded in latin-1
gname: 'root',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 512
})

stream.pipe(concat(function (data) {
Expand Down Expand Up @@ -618,7 +630,8 @@ test('gnu', function (t) { // can correctly unpack gnu-tar format
gname: 'mygroup',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 512
})

stream.pipe(concat(function (data) {
Expand Down Expand Up @@ -659,7 +672,8 @@ test('gnu-incremental', function (t) {
gname: 'mygroup',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 512
})

stream.pipe(concat(function (data) {
Expand Down Expand Up @@ -730,7 +744,8 @@ test('unknown format attempts to extract if allowed', function (t) {
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 512
})

extract.on('entry', onfile2)
Expand All @@ -754,7 +769,8 @@ test('unknown format attempts to extract if allowed', function (t) {
gname: 'staff',
devmajor: 0,
devminor: 0,
pax: null
pax: null,
contentsByteOffset: 1536
})

stream.pipe(concat(function (data) {
Expand Down
Loading