Re: Can't create temporary file
Re: Can't create temporary file
- Subject: Re: Can't create temporary file
- From: Rick Mann <email@hidden>
- Date: Thu, 19 May 2011 22:35:51 -0700
On May 19, 2011, at 22:31 , Quincey Morris wrote:
> On May 19, 2011, at 21:53, Rick Mann wrote:
>
>> But frankly, that's a kludge. Cocoa is full of inconsistencies (like NSFileManager/NSFileHandle lacking modern file creation methods) forcing the (ab)use of another API. Sure, it works (I'm guessing), but it's ugly.
>
> It's in the eye of the beholder. From where I'm standing, it's deeply consistent -- NSData is my go-to class for writing N bytes of arbitrary data to a file. Why is N==0 an abuse?
>
> Also, if I create a mutable data object:
>
> NSMutableData* dataBuffer = [NSMutableData data];
>
> then I can use it to create the file and then re-use it as the data buffer I need to pass to [NSFileHandle writeData:].
>
> With this technique, I've reduced the number of lines of boring housekeeping code needed to create the file and set up a data buffer I wanted anyway. Concision is good.
>
> With this technique, I've abstracted my task -- writing data bytes to a file in one or more pieces -- away from a series of lower level tasks (interacting with a file system) that have no particular interest. Abstraction is good.
I don't see how the NSData write allows me to append to an open file.
>
> Finally, you don't have to guess that it works. It's a line of code I've used many times. When posting code here to save you a little time and effort, I wouldn't waste your time suggesting doubtful code.
I appreciate that.
But the entire email thread could've been avoided if there were methods with obvious names (like createFileURL: or whatever). Or if NSFileHandle write... would have created the file, like NSData's write... does.
Those are the inconsistencies I refer to.
--
Rick
_______________________________________________
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