I'm new to this community and also new to iOS development, and I hope that someone can help me with a little problem...
Currently I'm writing a little app for myself, that should create a very large dummy file, with dummy data or words or whatever it makes it big.
The reason is, I would like to click a button and the app should generate a 4 gb file and save it to disk, that no other app could use it, because it isnt free... If I need the 4 gb of free space, I just have to open my little app, and after clicking another button, the file will be deleted, and i got 4 gb of free diskspace...
I know how to write files to disk but I have no idea how to generate a large amount of data in short time, to make it 4 or more gb big???
Does someone have an idea how to generate such a big file with a for loop or something?
Windows:
Open the command shell - cmd Execute the following command in order to create a file of 1mb
Linux:
Use convert and copy command - dd
OS X & Solaris:
If you do rough calculation by 1000, not by 1024
And exactly it will be 34359738368 bits
And if you go on to write that much characters (a b c etc) to a text file, by loop, you will create a file of 4gb.
If you just want to occupy 4GB of disk space, then create a file, seek to 4GB and write a byte. This will create a "sparse file" containing next-to-no data in next-to-no time!
This is C:
EDIT Dropped
creat()
in favour ofopen()
so the file mode can be specified.Also error checking should be better than shown...
You can create an
NSMutableData
object and use-setLength:
to expand it to 4GB. (-setLength
will fill with zeros), before writing it out to a file.I'm not sure how well iOS will cope with an
NSMutableData
object that large, however.Edit: Example:
Bear in mind also that iOS will purge your app's data in certain directories if the device's available storage is low.
You can just write it in C, incrementally:
Memory consumption will not be an issue here. Of course, it will take some time to write the entire file, as it is I/O bound. You will probably want some real data in there one day, too :)