• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Reading from the "almost end" of a file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: Reading from the "almost end" of a file
      • From: Public Look <email@hidden>
  • Prev by Date: How to use color panel to change color of font effects?
  • Next by Date: Re: focus ring around button
  • Previous by thread: How to use color panel to change color of font effects?
  • Next by thread: Re: Reading from the "almost end" of a file
  • Index(es):
    • Date
    • Thread