On Apr 15, 2008, at 10:38 AM, Nick Rogers wrote:
but i want to write the length of (NSData *)data, before I write it to file because I will be writing a lot of NSData to the file, so that I will be able to read the length first and then read the following NSData. SO how can I write the length which is an integer to file before I write the NSData.
Don't use NSFileHandle, then. Use NSOutputStream, open it on the file (I don't think you have to create the file beforehand) and use its - write:maxLength: method to write whatever bytes you want.
(Though to be honest, I don't ever do this. If I want to read and write bytes from raw files like that, I just use the standard C APIs like fopen, fread, fwrite...)
But are you really sure you need to roll your own file format and I/O code for this? It's annoying code to write, it has to deal with byte- ordering issues, and bugs in your code will often have nasty side effects like corrupting files or even allowing a maliciously-crafted file to take over your app. Why not just collect the NSDatas in an NSArray and call -writeToFile: on it? Then you could be done with the whole task in two minutes.
—Jens
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]