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

feat: Add ReadAt function for fileNode to allow gobinary extractor to successfully extract. #371

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

another-rex
Copy link
Collaborator

The gobinary extractor expects a ReaderAt, but fileNode does not implement it. The underlying file does though, so this just exposes it.

Copy link

@mleyvajr100 mleyvajr100 left a comment

Choose a reason for hiding this comment

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

Thanks for adding the ReadAt method Rex! Looks good, though tests might be a good idea.

@@ -67,6 +67,20 @@ func (f *fileNode) Read(b []byte) (n int, err error) {
return f.file.Read(b)
}

// Read reads the real file referred to by the fileNode.
Copy link

@mleyvajr100 mleyvajr100 Jan 2, 2025

Choose a reason for hiding this comment

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

Comment should start with "ReadAt".

You think we could refactor the Read method? Wondering if Read(b) is equivalent to ReadAt(b, 0).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's not quite the same, ReadAt will return io.EOF error if the buffer is bigger than what is there to read, but Read won't do that unless you do a second Read at the end of the file.

Choose a reason for hiding this comment

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

Gotcha. The code lgtm then!

@@ -67,6 +67,20 @@ func (f *fileNode) Read(b []byte) (n int, err error) {
return f.file.Read(b)
}

// Read reads the real file referred to by the fileNode.
func (f *fileNode) ReadAt(b []byte, off int64) (n int, err error) {

Choose a reason for hiding this comment

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

Oh, it might also be a good idea to add a few tests? Probably doesn't many given the Read method is sufficiently tested.

Copy link
Collaborator Author

@another-rex another-rex Jan 3, 2025

Choose a reason for hiding this comment

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

Good idea, added the tests! We might want to switch the wantErr in other tests to use the cmp library, since that also fails when wantErr is true but no error is returned.

Choose a reason for hiding this comment

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

Yeah.... I'll create a bug to remind myself of changing wantErr from other tests. Thanks for the note and the added tests!

@@ -67,6 +67,20 @@ func (f *fileNode) Read(b []byte) (n int, err error) {
return f.file.Read(b)
}

// Read reads the real file referred to by the fileNode.
func (f *fileNode) ReadAt(b []byte, off int64) (n int, err error) {

Choose a reason for hiding this comment

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

Yeah.... I'll create a bug to remind myself of changing wantErr from other tests. Thanks for the note and the added tests!

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.

2 participants