Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append NSData to a file in Objective C

I'm attempting to download a large file on the iPhone and save it to disk as it is downloaded.

Ideally, in:

-(void)connection:(NSURLConnection*)connection didReceiveData:(NSData*)data {

}

I want to append 'data' to a file on disk.

I've checked out the NSData documentation. There are functions to write to a file, but I can't see anything to append to an existing file.

Does anyone know how I can append this data? Any help much appreciated! Nick.

like image 745
Nick Cartwright Avatar asked Aug 10 '09 14:08

Nick Cartwright


1 Answers

You can use a combination of -writeData: and -seekToEndOfFile methods from NSFileHandle class for writing NSData to the end of a file.

like image 80
mouviciel Avatar answered Nov 10 '22 23:11

mouviciel