Monday, July 5, 2010

ZipKit: Compress and Extract Zip Files Programatically

My Problem:
Download and store a web page that could have multiple resources embedded into the html (e.g. links to pictures, css files, etc.). Why is this a problem? Because I have discovered that there is no way to save a web page programmatically in the iPhone SDK (at least using the 3.x OS). I could download and save each resource separately, but that means parsing the HTML to find each resource, download the resource, and then replace any absolute URLs with relative URLs in every file. A pretty gnarly task indeed.

The Circumstances:
Fortunately I have one thing on my side: I can dicate how I want the web page to exist. That's pretty huge: for example, I can require that it is packaged into a zip file, so I only need to download one file instead of hunting through the html to figure out what all needs to be downloaded.

The Solution:
A nifty library called ZipKit.

There are a couple of considerations that I will have to experiment with before I am satisfied with this solution:

  • How long does it take to unzip the types of zip files I am expecting?
  • If it does take a significant amount of time, how does that compare to the amount of time saved by downloading a compressed (read smaller) zip file?
  • Would a tar file work better, since it does not compress files - you have the full download time of the uncompressed files, but potentially a faster extraction speed (the OS doesn't have to run through a decompress operation)?
  • Can I read directly from the zip/tar file without extracting the files?
Of course, if someone has a suggestion for a better solution to my problem, I am all ears!

3 comments:

  1. I have recently been presented with the exact same task described above with an IPad app I am working on. I'm curious...were you successful with the above approach and how did the end result turn out for you?

    ReplyDelete
  2. I was successful, actually! ZipKit worked like a charm. The unzip process was fast, too. You can see for yourself how it worked: http://itunes.apple.com/app/daily-ignatian-reflections/id395830983?mt=8

    ReplyDelete
  3. Great, thank you! Glad to hear it was a success.

    ReplyDelete