-
Notifications
You must be signed in to change notification settings - Fork 18k
io: Seeker documentation does not match implementations #48316
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
Comments
Given that nearly every implementation in the standard library deviates from the documented
|
Change https://golang.org/cl/349054 mentions this issue: |
The current clause was added in https://golang.org/cl/11403043 (along with the inconsistent |
Does that mean that seeking will never return an error and only error on the next io op? If that's the case- why not simply state so? |
No. In practice (in ~all existing implementations), Some implementations return an error from In practice, if you want to use |
In that case I could imagine the following to make it clearer:
|
As far as I can tell, the existing For example, Ideally, I think we would require |
What version of Go are you using (
go version
)?go1.17
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?N/A
What did you do?
Read https://pkg.go.dev/io@go1.17#Seeker. Compare the behavior it requires to the implementations of that interface in the standard library.
What did you expect to see?
Behavior matching the documentation (emphasis mine).
The use of “and” here implies that implementations must return the current offset regardless of any error.
To me, “is legal” implies “does not result in an error”.
What did you see instead?
Many implementations reject positive offsets that exceed the size of the entity being read:
debug/elf.readSeekerFromReader
:go/src/debug/elf/reader.go
Line 80 in 2ebe77a
embed.openFile
:go/src/embed/embed.go
Line 371 in 90c5660
testing/fstest.openMapFile
:go/src/testing/fstest/mapfs.go
Line 194 in 213e157
io.SectionReader
has a particularly subtle variation on this. It represents the offset relative to the base of the section being read and fails to detect overflow:go/src/io/io.go
Line 519 in 90c5660
It isn't obvious to me whether
os.File.Seek
ever rejects positive offsets, since it passes the offset through to a platform-specific system call.On error (for example, when the offset overflows or is otherwise invalid, or when an underlying system call fails), most implementations return
0
instead of “the new offset relative to the start of the file”.bytes.Reader
:go/src/bytes/reader.go
Line 131 in 2ebe77a
debug/elf.readSeekerFromReader
:go/src/debug/elf/reader.go
Line 81 in 2ebe77a
embed.openFile
:go/src/embed/embed.go
Line 372 in 90c5660
os.File
:go/src/os/file.go
Line 243 in a25c584
strings.Reader
:go/src/strings/reader.go
Line 130 in 2ebe77a
testing/fstest.openMapFile
:go/src/testing/fstest/mapfs.go
Line 195 in 213e157
The text was updated successfully, but these errors were encountered: