On Fri, 2 Aug 2002 07:43:57 +0900 Florian Frank <flori / eavesdrop.ping.de> wrote: > BTW: If the filesize suddenly shrinks, copy and truncate could have > happened. I'm not sure what has to be done in this case. Rewinding to > the top of the file would perhaps be reasonable, because it doesn't make > much sense for a logfile to be truncated to any other filesize but 0. This makes sense to me. > > def wind(lines) [ ... ] > Maybe I am missing somtehing, but couldn't this be done much simpler > like this: > > def wind(lines) [use readlines] > end > end No, that's much better. I was thinking in terms of doing the opposite of what I did for rewind, missing the easier solution. > > def rewind(lines) [ ... ] > > end > > My approach is much more complicated because I use a buffer of an > arbitrary size, to spare some seek-calls and to have fewer > explicit iterations. Perhaps it doesn't make much of a difference and I > could use this simpler method. I should probably benchmark both methods > to find this out. If you want to tail beginning at an arbitrary position in the file, that will work, but many will probably want to specify the # of lines from the end. You could seek to the end, then seek backwards in chunks, read in each chunk, then count backwards through the chunk counting newlines and keeping track of filepos, and once you hit the # lines you want, seek to that position and then read from there. This would cut down on the # of seeks and reads in my method above, probably resulting in much better performance. Jim