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

os: File.SeekLine method #23219

Closed
StoicPerlman opened this issue Dec 22, 2017 · 3 comments
Closed

os: File.SeekLine method #23219

StoicPerlman opened this issue Dec 22, 2017 · 3 comments

Comments

@StoicPerlman
Copy link

@StoicPerlman StoicPerlman commented Dec 22, 2017

Wanted to see if there was any interest in this feature for os.File. Link below. Works just like Seek, except it steps by newlines.

Go is a big project, so before I went to the trouble of making a legit patch and making sure I don't break anything I wanted to see if there was interest in adding it.

https://github.com/StoicPerlman/fls

@davecheney
Copy link
Contributor

@davecheney davecheney commented Dec 22, 2017

@mvdan
Copy link
Member

@mvdan mvdan commented Dec 22, 2017

There are already pieces in the standard library for working with lines, such as https://golang.org/pkg/bufio/#Scanner. Or, if you need to go backwards and forwards instead of in a stream, you should instead split the input into a slice of lines with strings.Split or bytes.Split.

I also think that this is an unnecessary clutter of os.File. It absolutely doesn't need to know what a line is.

@StoicPerlman
Copy link
Author

@StoicPerlman StoicPerlman commented Dec 22, 2017

I figured that would be the answer. The ultimate goal for this is to be able to seek by any delimiter, but handling a > 1 byte delimiter adds some complexity that I didn't feel like doing before I knew if there was interest. I personally think seeking through a file for a delimiter is a pretty basic function.

The reason this was necessary is because nothing in bufio can seek line by line and return the position in the file. So Scanner could not meet my use case.

If anyone else stumbles on this and needs it feel free to checkout fls.

@titanous titanous closed this Dec 22, 2017
@mikioh mikioh changed the title os.File SeekLine function os: File.SeekLine method Dec 27, 2017
@golang golang locked and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.