A better way to do this would be to utilize the io.Reader interface.
[0] https://github.com/polegone/gonix/blob/0b65cd4fb9c6c44357d0a...
A better way to do this would be to utilize the io.Reader interface.
[0] https://github.com/polegone/gonix/blob/0b65cd4fb9c6c44357d0a...
By the way, I'm wondering how I should go through the file line by line with a reader.
I think the most efficient way may be to scan byte by byte from the start (head) or the end (tail), and count until reaching n amount of newlines (or stop if at the end of the file), then print the bytes between the start/end and the nth newline.
How does this sound?
In the end I settled for reading it from the start which worked 99.999% of the time and enabled me to finish the project to the tight deadline I had. But I've always meant to go back and "fix" that code at some point.
Take a look at my Go package that allows you to programmatically do 'tail -f' - https://github.com/activestate/tail
I found the optimal value of AVERAGE_CHARS_PER_LINE to be around 40 characters, but of course it hugely depends on the file being read.