Re: Issue with read/write to NSFileHandle
Re: Issue with read/write to NSFileHandle
- Subject: Re: Issue with read/write to NSFileHandle
- From: Jens Alfke <email@hidden>
- Date: Thu, 30 Jun 2016 09:18:43 -0700
> On Jun 29, 2016, at 8:40 PM, Graham Cox <email@hidden <mailto:email@hidden>> wrote:
>
> Reading the documentation, NSFileHandle seems to have only one file offset, which is common to both read and write, which is a bit puzzling, because surely you’d want to write at the end of the file, but read from wherever you’d read from last time.
NSFileHandle is just exposing the semantics of a file stream, i.e. a standard C `FILE*`, or a Unix file-descriptor. Every file I/O API I can think of, on any platform, has this behavior — there is a single offset that’s used for reads and writes. It may not make sense to you, but it’s been that way since at least 1969 :)
So yeah, you’ll need two handles, one to write and one to read. But I have doubts that the readabilityHandler is going to work — I don’t know if it will actually detect that the EOF on the file has advanced. This kind of handler is intended for non-seekable streams like sockets or pipes.
If I were going to implement a custom logging console, I’d write to a “.log” file and have Console.app open the file, since it’s quite good at displaying logs and updating them in real time.
—Jens
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden