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

Conversation

doxavore
Copy link

When emitting the header for an entry event, the contentsByteOffset property is added to the header object. This property is the byte offset of the start of the entry's file contents in the tar stream, after the header.

This is useful when building an index of a tar's contents, for later seeking to a specific entry's contents in the tar stream.

Headers can be variable length based on the tar implementation.

Fixes #162. I'm happy to change this if we prefer a different approach.

When emitting the header for an entry event, the contentsByteOffset
property is added to the header object. This property is the byte offset
of the start of the entry's file contents in the tar stream, after
the header.

This is useful when building an index of a tar's contents, for later
seeking to a specific entry's contents in the tar stream.

Headers can be variable length based on the tar implementation.
extract.js Outdated
@@ -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! 🙏

@mafintosh
Copy link
Owner

nice, commented

@doxavore doxavore requested a review from mafintosh January 15, 2025 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Is it possible to return raw file offsets from within the tar?
2 participants