by misframer · 11y ago · 0 comments
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?
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.