[SOLVED] Re: length of file from NSFileHandle?
[SOLVED] Re: length of file from NSFileHandle?
- Subject: [SOLVED] Re: length of file from NSFileHandle?
- From: Graham Cox <email@hidden>
- Date: Sat, 27 Aug 2016 21:18:19 +1000
> On 27 Aug 2016, at 1:41 PM, Ken Thomases <email@hidden> wrote:
>
> The reason it has no length property is because not all NSFileHandles have the concept of a length. For example, a file handle associated with a pipe or socket.
Right, though for those cases it could just return 0 or some other marker (or throw).
> For an on-disk file, you can seekToEndOfFile and get offsetInFile to determine the file length. If you need to not perturb the file position, you can record the original offsetInFile and then seekToFileOffset:origOffset to restore it after measuring the length.
After I posted I noticed that -seekToEndOfFile returns the length, and I was calling that anyway (to append to the file), so it was an obvious solution I’d missed.
> Matthew Emerson's suggestion of using fstat() with the fileDescriptor is also reasonable.
I was about to head down that path when I noticed the above - thanks for the suggestions anyway, worth knowing for the future.
—Graham
_______________________________________________
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