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

embed: guarantee (*FS).Open's returning value implements io.Seeker #45745

Closed
hajimehoshi opened this issue Apr 24, 2021 · 10 comments
Closed

embed: guarantee (*FS).Open's returning value implements io.Seeker #45745

hajimehoshi opened this issue Apr 24, 2021 · 10 comments
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@hajimehoshi
Copy link
Member

hajimehoshi commented Apr 24, 2021

From the current document, there is no guarantee whether (*embed.FS).Open's returning value implements io.Seeker or not.

Open opens the named file for reading and returns it as an fs.File.

IIUC the returned value always implements io.Seeker in the current implementation, and actually it is fine to assume this (e.g., #44175 (comment)). Would it be possible to make the current behavior explicit in the document?

@gopherbot gopherbot added this to the Proposal milestone Apr 24, 2021
@hajimehoshi
Copy link
Member Author

CC @ianlancetaylor

@josharian
Copy link
Contributor

Embedded directories do not implement Seek. (This bit me yesterday.)

@hajimehoshi
Copy link
Member Author

Ah, I see. So I want a guarantee that (*embed.FS).Open returns a fs.File that implements io.Seeker when the returned value is a file, not a directory.

@josharian
Copy link
Contributor

Yep. Or we could make directories seekers too, I guess.

@ianlancetaylor
Copy link
Contributor

I think it would be fine to document that the result of embed.FS.Open, when opening a file that is not a directory, will implement io.Seeker.

@ianlancetaylor
Copy link
Contributor

This doesn't have to be a proposal, so taking it out of the proposal process.

@ianlancetaylor ianlancetaylor changed the title proposal: embed: guarantee (*FS).Open's returning value implements io.Seeker embed: guarantee (*FS).Open's returning value implements io.Seeker Apr 24, 2021
@ianlancetaylor ianlancetaylor added Documentation NeedsFix The path to resolution is known, but the work has not been done. and removed Proposal labels Apr 24, 2021
@ianlancetaylor ianlancetaylor modified the milestones: Proposal, Backlog Apr 24, 2021
@hajimehoshi
Copy link
Member Author

hajimehoshi commented Apr 25, 2021

Yep. Or we could make directories seekers too, I guess.

This sounds better to me, as *os.File has Seek even for directories. Always returning an error at openDir.Seek should be fine.

I think it would be fine to document that the result of embed.FS.Open, when opening a file that is not a directory, will implement io.Seeker.

Hmm, always having Seek sounds less confusing. What do you think?

@tmthrgd
Copy link
Contributor

tmthrgd commented Apr 25, 2021

While it might be true currently, wouldn’t adopting this make it impossible/much-more-difficult for the compiler to change how embedded files are stored? For instance to automatically compress them. I seem to recall being able to decide that kind of thing at a later time was part of the original proposal or discussion.

@ianlancetaylor
Copy link
Contributor

I suppose I don't see a reason to support Seek for embedded directories. And we don't support it today.

Since we already support Seek for embedded files, it's going to be pretty hard to change that. We can still compress the embedded data, we'll just have to decompress the entire file if it is opened.

@gopherbot
Copy link

Change https://golang.org/cl/313352 mentions this issue: embed: guarantee the returned file of FS.Open implements io.Seeker

@golang golang locked and limited conversation to collaborators Sep 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants