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

proposal: archive/tar: export Reader.handleRegularFile() #45122

Closed
mschneider82 opened this issue Mar 19, 2021 · 1 comment
Closed

proposal: archive/tar: export Reader.handleRegularFile() #45122

mschneider82 opened this issue Mar 19, 2021 · 1 comment

Comments

@mschneider82
Copy link

When you know the position and size of an entry of a tar archive, you could Seek to that position and read just the entry.
Unfortunately this is currently not possible because there is no exported function on the Reader where you can use an custom tar.Header.

I suggest to export the tar.Reader handleRegularFile() function to make Seeking possible.

This works fine, when HandleRegularFile is exported:

	f, err := os.Open(tarFile)
	if err != nil {
		return nil, err
	}
        defer f.Close()

	_, err = f.Seek(startPos, 0)
	if err != nil {
		return nil, err
	}

	tr := tar.NewReader(f)
	hdr := &tar.Header{
		Name: entryName,
		Mode: 0600,
		Size: int64(entrySize),
	}
	if err := tr.HandleRegularFile(hdr); err != nil {
		return nil, err
	}

        content, err := io.ReadAll(tr)
@gopherbot gopherbot added this to the Proposal milestone Mar 19, 2021
@mschneider82
Copy link
Author

it turns out that HandleRegularFile doesnt match the content of the file. Needs further investigation to seek into tars. Closing this for now

@golang golang locked and limited conversation to collaborators Mar 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants