Titanium Appcelerator and Zipfile module

I was working on an Titanium Appcelerator project yesterday where I needed to download a zip file to a mobile device, then extract its contents. After doing a little research, I found the Titanium Zipfile module out on Github. Ultimately, this is exactly what I needed, but there were some stumbling blocks along the way so I thought I’d document them (and the solutions) here.

First off, the latest Zipfile module (as of this writing) is version 0.1.21. This version is not available as a binary download from the Github repository. Fortunately, this post led me to a download for it.

I found this nice piece of code Dan Tamas posted in an answer to a question about downloading image files. I promptly copied that off to a FileManager.js file to ‘require’ into the app.

As I started testing, it wasn’t working and I didn’t know whether the file wasn’t getting downloaded or wasn’t getting extracted. By default, my simulator run configuration was setup for INFO. Turning to DEBUG revealed that it wasn’t able to locate the zip file. After checking that paths were being set correctly, I found this note at the Github project’s issues tab that applies to the 1.8x SDK codestream.

Replacing the following example code from the documentation:

  1. zipfile.extract(  
  2.   Ti.Filesystem.applicationDataDirectory+‘/Archive.zip’,  
  3.   Ti.Filesystem.applicationDataDirectory);

with this:

  1. var appDir = Ti.Network.decodeURIComponent(  
  2.   Ti.Filesystem.applicationDataDirectory).replace(  
  3.   ‘file://localhost’, );  
  4. zipfile.extract(appDir+‘Archive.zip’, appDir);

did in fact solve the issue and everything works great from there.

6 thoughts on “Titanium Appcelerator and Zipfile module

  1. I have a problem with the overall premise of your article but I still think its really informative. I really like your other posts. Keep up the great work. If you can add more video and pictures can be much better. Because they help much clear understanding. :) thanks

  2. This doesn’t work iOS 7. Please find me a solution for this. I have researching on it and it seems to be hectic to find a solution.

  3. I’m sorry, but it’s not my responsibility to find a solution to this for you. I share information here because I choose to do so on items I find of interest. My doing so does not imply an obligation on me to support anyone in their work efforts at my time and cost. I suggest you apply your own ingenuity and come up with an appropriate solution for new requirements. :-)

  4. Pingback: This Week in Titanium Mobile Development: 23 Jan 2012 | TiDev

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>