Reading from the "almost end" of a file
Reading from the "almost end" of a file
- Subject: Reading from the "almost end" of a file
- From: Yann Bizeul <email@hidden>
- Date: Tue, 17 Feb 2004 10:09:00 +0100
Hi list,
I would like to use NSFileHandle to reproduce the behavior of tail in
terminal.
As seen in the list, what I did and is working is opening the file,
and set a 10ms NSTimer to get availableData on the NSFileHandle. That's
perfect, and not CPU intensive as I thought.
Actually, I do this :
fh = [ NSFileHandle fileHandleForReadingAtPath: [ self file ]];
int offset = [ fh seekToEndOfFile ];
[ fh closeFile ];
fh = [[ NSFileHandle fileHandleForReadingAtPath: [ self file ]]
retain ];
offset = (offset - 2000);
if (offset < 0) offset=0;
[ fh seekToFileOffset: offset];
But it does not seek to the 2000th byte before the end but directly to
the end of the file.
What's the good way to do this, is there a quick way to say "from 10th
*line* of the file before the end"
Thank you
--
Yann Bizeul - yann at tynsoe.org
http://projects.tynsoe.org/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.