views:

54

answers:

3

Hi everyone.

I've got some old code on a project I'm taking over. One of my first tasks is to reduce the final size of the app binary. Since the contents include a lot of text files (around 10.000 of them), my first thought was to create a database containing them all.

I'm not really used to SQLite and Core Data, so I've got basically two questions:

1 - Is my assumption correct? Should my SQLite file have a smaller size than all of the text files together? 2 - Is there any way of automating the task of getting them all into my newly created database (maybe using some kind of GUI or script), one file per record inside a single table?

I'm still experimenting with CoreData, but I've done a lot of searching already and could not find anything relevant to bringing everything together inside the database file. Doing that manually has proven no easy task already!

Thanks.

A: 

1 - It probably won't be any smaller, but you can compress the files before storing them in the database. Or without the database for that matter.

2 - Sure. It's shouldn't be too hard to write a script to do that.

ldav1s
How would I compress them before storing in the database? From what I've learned, I can use a few image type files, PFDs and TXTs only. Am I mistaken? And what kind of compression would you suggest if I didn't use the database? Like I asked Martin, wouldn't that represent a performance hit?
Aloha Silver
See [here](http://stackoverflow.com/questions/230984/compression-api-on-the-iphone) for more info on iPhone compression libs. You'd compress them before copying into the Xcode project I guess. zlib compression is less CPU intensive bzip2 routines (generally). Of course compression will affect performance, but you'll have to see if you can live with it. I'd use zlib, without any knowledge of your files/app performance. It's fairly fast and crunches text files down fairly small.
ldav1s
A: 

If you're looking for a SQLite bulk insert command to write your script for 2), there isn't one AFAIK. Prepared insert statments in a loop inside a transaction is the best you can do, I imagine it would take only a few seconds (if that) to insert 10,000 records.

miket2e
Can you point me to any tutorials of similar ideas? Sorry about it, but I'm really knew to SQLite databases, and I know next to nothing about them.
Aloha Silver
A: 

An alternative to using SQLite might be to use a zipfile instead. This is easy to create, and will surely safe space (and definitely reduce the number of files). There are several implementations of using zipfiles on the iphone, e.g. ziparchive or TWZipArchive.

Martin v. Löwis
My main concerns about zip files are two: since the text files weight at around 100 MB (all of them together), unzipping would be a performance hit, wouldn't it? And also, the final app, an .ipa file, already compresses everything. It would be something like a .zip inside a .zip. Would that really save me more space?
Aloha Silver
You shouldn't need to really unzip the entire file, ever. Instead, you should extract only those files that you are going to use. As for ipa being zip files already: I don't know whether they get extracted on the iphone; if yes, it may still be useful to have a zipfile inside the zipfile. However, for the size of the ipa file, it will make no difference. I doubt anything discussed will make a difference - you really need to find redundancy in the text files themselves that zip is not able to find.
Martin v. Löwis