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: io/v2: remove io.Seeker, SeekStart, etc., change Seek method #25854
Comments
I looked through all my own code and the Go code at my company.
|
SeekCurrent is generally only used with 0 to learn the current seek position, and often just to restore it at the end of some operation that really wanted an |
I support the proposal to reduce the That said, I wouldn't discount use-cases for Roughly speaking: f.Seek(n, SeekStart) => f.Seek(n)
f.Seek(n, SeekCurrent) => f.Seek(f.CurrentOffset()+n)
f.Seek(n, SeekEnd) => f.Seek(f.EndOffset()+n)
I much rather see idiomatic methods to access the current offset and end offset than separate |
os.File is an API to the OS. Second-guessing the OS model for that API could have unintended consequences. If you must change os.File.Seek, please a) rename os.File.Seek to .SeekFrom, and For an append-only file with an index at file's end, I use seek-from-end to read the index size, then seek-from-current to read the index. Thanks! Edit: |
If the underlying |
Copying @bradfitz's comment #17920 (comment) into a separate proposal.
For Go 2 we should consider changing the
Seek
method to just take a file position, not a whence argument. We should consider addingSeekFromCurrent
andSeekFromEnd
, though I suspect they are unnecessary. We should changeSeeker
similarly. We should removeio.SeekStart
,io,SeekCurrent
, andio.SeekEnd
.Rationale: the current
Seek
method is copied from C. It presents three different interfaces, and doesn't make much sense as a single method in Go. People who implement theio.Seeker
interface often only implement it forio.SeekStart
, and do not correctly handle the other possible values.See also #17920, which this would replace.
The text was updated successfully, but these errors were encountered: