bandw
bandw

Reputation: 889

Create a certain size file and filled with no data on iOS

I'm developing an iphone app, I need to create a certain size file on filesystem and filled with NO data first, then seek to a offset and write data when get data from somewhere else
How can I do it?

Upvotes: 1

Views: 1025

Answers (2)

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81858

The lseek BSD function is explicitly capable of that.

man lseek:

The lseek() function allows the file offset to be set beyond the end of the existing end-of-file of the file. If data is later written at this point, subsequent reads of the data in the gap return bytes of zeros (until data is actually written into the gap).

Upvotes: 4

nacho4d
nacho4d

Reputation: 45088

NSMutableData or fseek is probably what you want

Upvotes: 1

Related Questions