Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

ZipFile — Mobile Titanium module (iPhone)

I started develop titanium module that add functions to working with zip files. (ZipArchive wrapper) Fist version has only one method to extracts files from zip archive.But I plan to add new functionality soon. For more information please visit github repo

Example:

//app.js: download zip from DropBox to Documents folder
//        and extact file to Documents folder

Titanium.UI.setBackgroundColor('#000');

var win1 = Titanium.UI.createWindow({
      title:'ZipFile test',
      backgroundColor:'#fff'
});

win1.open();
var xhr = Titanium.Network.createHTTPClient();

xhr.onload = function()
{
   var f = Ti.Filesystem.getFile(
    Ti.Filesystem.applicationDataDirectory,
    'test.zip'
   );
   f.write(this.responseData);
   Ti.API.log('INFO',Ti.Filesystem.applicationDataDirectory);
   Ti.ZipFile.extract(
      Ti.Filesystem.applicationDataDirectory+'/test.zip',
      Ti.Filesystem.applicationDataDirectory
   );
};
xhr.open('GET','http://dl.dropbox.com/u/1400234/test.zip');
xhr.send();
— asked June 30th 2010 by Gennadiy Potapov
  • iphone
  • module
  • unzip
  • zip
3 Comments
  • i copied the directions from the repo's more info page and am getting this error:

    line = 18;
    message = "Result of expression 'Ti.ZipFile' [undefined] is not an object.";

    earlier in the log, i'm getting this message:

    [DEBUG] Detected module for iphone: com.generalarcade.ZipFile 0.1.18 @ /Library/Application Support/Titanium/modules/modules/iphone/zipfile/0.1.18
    [DEBUG] Looking for Titanium Module id: zipfile, version: 0.1.18, platform: <any platform>

    any ideas what's going wrong?

    — commented February 24th 2011 by Jack Finch
  • Some issue here too. I'd really need this, since it will be invaluable for uploading multiple files which I can unzip on my server.

    — commented March 4th 2011 by Kosso
  • Create a new module using the latest guide [ http://guides.appcelerator.com/en/module_ios.html ], and make sure you're using 1.6.0. Then dump in his resources. This works for me.

    — commented March 5th 2011 by Kosso

30 Answers

  • So that people dont have to dig through comments, here's the compiled source for 0.1.21:

    http://kosso.co.uk/stuff/zipfile-iphone-0.1.21.zip

    — answered October 20th 2011 by Cameron Chunn
    permalink
    5 Comments
    • I download this version and installed
      It's not do any thing after loaded in the three way that I try..

      Code & path struction
      Log

      — commented January 3rd 2012 by mosluce chen
    • Same here - I see [INFO] [object ZipfileModule] loaded and then run all combinations of the code and get no output of any kind - no errors, no unzipped files.

      I am using 1.8.2.

      Is this module working for anybody? I am using the 0.1.21.zip precompiled file.

      — commented April 12th 2012 by Matthew Delmarter
    • Worked for me for a real long time. Recently upgraded to lion, and zipfile is no longer working in the emulator. going to try it on device next.

      — commented April 13th 2012 by David Jones
    • just want to add a note that it looks like you need to do a full build after you add the module, otherwise it will fail silently, just as the above said, no errors, no unzipped file.
      I did make it work on Ti mobile SDK 2.0.1.GA2, Mac OS Lion. I'm using the git source (which is 0.1.21) and ran the build.py to build out the module, then installed the module to the global location as the README says, then add the module to the project, do a full rebuild (just removed all build files), and it works.

      — commented April 30th 2012 by Yi Yang
    • Is there plans to upgrade this module to v2 of the SDK ?

      — commented October 10th 2012 by Dallas Clark
  • I have made the android version (it only extracts for the moment).
    It is available on GitHub : androzip

    — answered April 26th 2011 by Henri Bourcereau
    permalink
    4 Comments
    • Nice one! :)

      — commented April 26th 2011 by Kosso
    • I can't get the android version working. Maybe I'm using a bad name for the folder or the zip file which contains the module.

      Which name should I use in zip file? Where do I have to put the zip file? I've tried copying it Library/AppSupport/Titanium/ also in the project root and inside resources but nothing works.

      Please, could you tell me the exact location and if I have to put the zip file or the uncompressed folder?

      All I get is a red screen telling me that is not able to find com.websiteburo.androzip.js
      I'm using version=0.1 in tiapp.xml Is that correct?

      — commented June 29th 2011 by Itinerarium Itinerarium
    • Never mind.Got it working, but the installation explanation in github is not complete. Henri, you should update it. It would make happy the module-noobs like me.

      If you want to get it working you have to manually create /Library/Apllication Support/Titanium/modules/android/androzip/0.1/
      Inside that path put androzip.jar (which is located in the dist folder of the downloaded code).

      Maybe this is not the only way to get it working but it's the one that has worked for me.

      — commented June 29th 2011 by Itinerarium Itinerarium
    • Henri, thanks for this but I can't seem to get it to work. When I try deploying as you state, it can't find the file. When I do what Itinerarium stated, it builds but I get an odd "missing ; before statement with the following source at location [1,43]<anonymous>: "(function(exports){NOT_FOUNDreturn exports;})({}). Any idea what I am doing wrong? I really want to use your module but can't get it to work.

      — commented June 30th 2011 by Kevin Eaton
  • var appDir = Ti.Network.decodeURIComponent(Ti.Filesystem.applicationDataDirectory).replace('file://localhost', '');
    zipfile.extract(appDir + 'test.zip', appDir);
    

    this can fixed the "Can't find zipfile"

    [DEBUG] zip opened
    [DEBUG] file unzipped
    
    — answered November 24th 2011 by Terry Xu
    permalink
    2 Comments
    • Thanks a lot. This solved my problem.

      — commented April 4th 2012 by Hans Zimmer
    • Yah… this can also be fixed thru javascript, removing file://localhost and uri-decoding (removing things like %20 and replacing them by "\ ", that is, spaces)…

      — commented April 30th 2012 by Ganna Kozynenko
  • I downloaded the latest build (0.1.21), put it in the right path, register it in tiapp.xml and my App says, the module is loaded

    [INFO] [object ZipfileModule] loaded
    [INFO] module is => [object ZipfileModule]
    

    BUT…..

    Then my zipped File is correctly loaded and nothing happens, it (the module) doesn't unzip the zipfile. What is my mistake?

    Sorry for my English an the question, I'm a Ti.Beginner.

    function loadunzip(){
        var xhr = Titanium.Network.createHTTPClient();
    
        xhr.onload = function()
        {
               var f = Ti.Filesystem.getFile(myDir.nativePath,'bilder02.zip');
               f.write(this.responseData);
               Ti.API.log('INFO',myDir.nativePath);
               Ti.ZipFile.extract(myDir.nativePath +'/bilder02.zip',myDir.nativePath);
          };
    
        xhr.open('GET', path+'bilder02.zip');
        xhr.send();
    };
    
    loadunzip();
    
    — answered June 27th 2011 by Marko Litzenberg
    permalink
    6 Comments
    • Try

      var zipfile = require('zipfile');
      zipfile.extract(myDir.nativePath+'/bilder02.zip', myDir.nativePath);
      

      — commented June 27th 2011 by Sebastian Klaus
    • :-(

      thank you — but no change

      — commented June 27th 2011 by Marko Litzenberg
    • Now I get a new console-output:

      [DEBUG] Can't find zip file
      [DEBUG] can't open zip
      

      But the file is in the path - I can see it and I can manually unzip it

      — commented June 27th 2011 by Marko Litzenberg
    • Since 1.7.0 the Filesystem has been changed to return a localhost url for properties such as applicationDataDirectory.

      var dataDir = Ti.Filesystem.applicationDataDirectory.slice(0,Ti.Filesystem.applicationDataDirectory.length - 1).replace('file://localhost','').replace(/%20/g,' ');
      zipfile.extract(dataDir+'/test.zip', dataDir);
      

      — commented June 27th 2011 by Sebastian Klaus
    • :-))
      Thank you — that's it. Now the unzip-process works fine

      — commented June 27th 2011 by Marko Litzenberg
    • i can get the unzip process to work, but i cant get the image to show. is there a way for me to see the contents of the zip file on the device itself?

      — commented November 18th 2011 by Mark Crippen
  • Help: I can't seem to get Zipfile installed.

    I get

    Script Error = Couldn't find module: zipfile.

    I have

    <modules>
        <module platform="iphone" version="0.1.18">zipfile</module>
    </modules>
    

    in my tiapp.xml

    and the files are located in /Library/Application Support/Titanium/Modules/iphone/zipfile/0.1.18

    Using the example code from the site, just trying to load the module at this time. Thanks to the author for the hard work, looking forward to working with it.

    — answered August 16th 2011 by David Jones
    permalink
    1 Comment
    • Got it to work by downloading the 0.1.21 build (above)

      Needed to delete my build folder and rebuild though.

      Great work Gennadiy

      — commented August 16th 2011 by David Jones
  • It now allows the creation as well. However, notice that it is iOS specific. It does not have a similar android module included.

    — answered November 10th 2010 by Doug Handy
    permalink
    0 Comments
  • Awesome Work, tested it out and works extremely nice.
    simple and easy to use!.

    If you want can you explain your work a bit?

    I'm trying to create a module myself for numerous things later, but I seem to get really confused about how the setup in modules is.

    I mean my test module i am trying to make something draggable using touch events,

    But how do go about this..everytime I get somewhere and seems to work, the build fails..
    I'm probally doing something wrong here, like declaring function or arguments in the wrong file etc.

    Anyway we need someone with this kind of experience to create a sort of tut/doc in which you create a simple view or something that way more people can try and make modules

    — answered November 10th 2010 by Patrick van Zadel
    permalink
    0 Comments
  • Hey - just curious if anyone has tried this with the latest Mobile build of Titanium? It appears to be detecting the module OK - but failing on completing the build.

    — answered December 10th 2010 by Bert Grantges
    permalink
    2 Comments
    • I'm getting the same error. I think it's tiapp.xml related…

      — commented February 7th 2011 by Adam Campbell
    • try the latest version

      — commented April 26th 2011 by Kosso
  • I get no "Detecting third-party module:"

    in my tiapp.xml I wrote "<module version="0.1.18">zipfile</module>", but Titanium didn't find the module.

    any ideas?

    — answered June 20th 2011 by Sebastian Klaus
    permalink
    6 Comments
    • Ah… I just looked at the readme and it appears that github didn't parse the tiapp.xml module element correctly. My bad.

      It needs to say this (for the current version on github) :

      <module version="0.1.21">zipfile</module>
      

      — commented June 20th 2011 by Kosso
    • Just updated the readme on github : https://github.com/kosso/ZipFile

      — commented June 20th 2011 by Kosso
    • sorry, nothing changed. renamed my folder in Titanium/modules/iphone/zipfile in 0.1.21, also in the tiapp.xml

      got no detection :-(

      downloaded newest version from github, build fails.
      here is the notice:
      The following build commands failed:
      CompileC build/ZipFile.build/Release-iphoneos/zipfile.build/Objects-normal/armv6/ZipfileModule.o Classes/ZipfileModule.m normal armv6 objective-c com.apple.compilers.gcc.4_2

      hope, this helps

      — commented June 20th 2011 by Sebastian Klaus
    • After adding the line to the tiapp.xml, did you delete the contents of the PROJECT/build/iphone/* folder before trying to rebuild?

      Try getting the module zip to install from here if you're having trouble building it yourself : http://kosso.co.uk/stuff/zipfile-iphone-0.1.21.zip

      — commented June 20th 2011 by Kosso
    • thanks, it works with your compiled version. great ;)

      — commented June 20th 2011 by Sebastian Klaus
    • I'm having a problem with 1.7.1 version, it just won't run, simulator starts and then it just crashes.

      — commented July 18th 2011 by Lukas Skrabak
  • Hi there, I'm desperately trying to get this module working but without luck.
    Every time I add this to my project it just won't run.

    I'm on mac, using TiStudio with 1.7.1 sdk, module is located in &#x2F;Volumes&#x2F;Mac&#x2F;Library&#x2F;Application Support&#x2F;Titanium&#x2F;modules&#x2F;iphone&#x2F;zipfile&#x2F;0.1.21&#x2F;, in tiapp.xml I have this &lt;modules&gt; &lt;module version=&quot;0.1.21&quot;&gt;zipfile&lt;&#x2F;module&gt; &lt;&#x2F;modules&gt; but app just crashes before executing.
    With this log:

    [INFO] One moment, building ...
    [DEBUG] Detecting modules in /Users/Master/Documents/Titanium Studio Workspace/virtualnezahorie/modules
    [DEBUG] Detecting modules in /Library/Application Support/Titanium/modules
    [DEBUG] Detected module for iphone: zipfile 0.1.21 @ /Library/Application Support/Titanium/modules/iphone/zipfile/0.1.21
    [DEBUG] Looking for Titanium Module id: zipfile, version: 0.1.21, platform: <any platform>
    [INFO] Detected third-party module: zipfile/0.1.21
    [INFO] Titanium SDK version: 1.7.1
    [INFO] iPhone Device family: iphone
    [INFO] iPhone SDK version: 4.3
    [INFO] iPhone simulated device: iphone
    [DEBUG] executing command: /usr/bin/killall iPhone Simulator
    [DEBUG] No matching processes belonging to you were found
    [DEBUG] finding old log files
    [DEBUG] executing command: mdfind -onlyin /Users/Master/Library/Application Support/iPhone Simulator/4.3 -name 48c986ed-31be-48ae-982a-40c99b21e2ea.log
    [INFO] Launching application in Simulator
    [INFO] Launched application in Simulator (14.22 seconds)
    [DEBUG] App Spec: <DTiPhoneSimulatorApplicationSpecifier 0x100303b50> specified by path /Users/Master/Documents/Titanium Studio Workspace/virtualnezahorie/build/iphone/build/Debug-iphonesimulator/virtualnezahorie.app
    [DEBUG] SDK Root: <DTiPhoneSimulatorSystemRoot 0x1003023f0> path=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk version=4.3 name=Simulator - iOS 4.3
    [DEBUG] using device family iphone
    
    [DEBUG] Session could not be started: Error Domain=DTiPhoneSimulatorErrorDomain Code=1 UserInfo=0x10011e7e0 "Unknown error."
    
    [INFO] Application has exited from Simulator
    
    — answered July 18th 2011 by Lukas Skrabak
    permalink
    1 Comment
    • Never mind I've found the source of the problem !

      Note to self NEVER use folder with name 'resources' inside your titanium app projects Resources, Xcode gets quickly lost and does not compile your app correctly.:)

      — commented July 18th 2011 by Lukas Skrabak
  • Where do I download the 0.1.21 version? I can only find versions 0.1.18 and 0.1.17 on github.. Maybe I am looking at the wrong place. Can someone help me find it?

    — answered October 20th 2011 by Nilesh Dosooye
    permalink
    2 Comments
    • http://kosso.co.uk/stuff/zipfile-iphone-0.1.21.zip … took me a while too.

      — commented October 20th 2011 by Cameron Chunn
    • Thanks a lot for the link ! Great module.. the 0.1.21 works perfectly !

      — commented October 20th 2011 by Nilesh Dosooye
  • Was functionality ever added to create zip files on Android with this module? I can't find it in the notes.

    — answered December 30th 2011 by Dominic Maricic
    permalink
    0 Comments
  • Hello, when i try to build the build.py i get the folowing error:
    The following build commands failed:
    CompileC build/ZipFile.build/Release-iphoneos/zipfile.build/Objects-normal/armv6/ZipfileModule.o Classes/ZipfileModule.m normal armv6 objective-c com.apple.compilers.llvm.clang.1_0.compiler
    (1 failure)
    xcodebuild failed

    does anybody knows what this means?

    — answered April 10th 2012 by Elmar Maan
    permalink
    0 Comments
  • Is there a newer compiled source that 0.1.21.zip?

    I noticed that there have been a few new commits on github.

    — answered April 12th 2012 by Matthew Delmarter
    permalink
    1 Comment
    • OK fixed the issue. The module works fine the problem I was having was alluded to in a hidden comment above - related to since 1.7.0 the Filesystem has been changed to return a localhost url for properties such as applicationDataDirectory.

      By using the following vars it now works:

      var resourceDir = Ti.Filesystem.resourcesDirectory.slice(0,Ti.Filesystem.resourcesDirectory.length - 1).replace('file://localhost','').replace(/%20/g,' ');
      
      var dataDir     = Ti.Filesystem.applicationDataDirectory.slice(0,Ti.Filesystem.applicationDataDirectory.length - 1).replace('file://localhost','').replace(/%20/g,' ');
      

      — commented April 13th 2012 by Matthew Delmarter
  • Thanks for the module. It works perfectly for what I need it to do. Is there something to listen for when zipfile is done unzipping?

    — answered June 13th 2012 by Eugene Gibson
    permalink
    0 Comments
  • Thanks for the module. It works perfectly for what I need it to do. Is there something to listen for when zipfile is done unzipping?

    — answered June 13th 2012 by Eugene Gibson
    permalink
    0 Comments
  • Upgraded my xcode and titanium now zipfile module seems to crash my app.. Pls help me asap.. it affects all my apps since I have used it to extract files from server..

    — answered September 27th 2013 by Kirthika VijayaKumar
    permalink
    1 Comment
    • Finally I came out with a solution.. Here's the link which can help zip file extractions: https://github.com/mpociot/titanium-mobile-zip-module/
      Thanks a ton mpociot..

      Happy Coding :)

      — commented October 16th 2013 by Kirthika VijayaKumar
  • Thanks for sharing this - it's something I'd planned to look into in the future. You didn't touch the license file though - are you allowing us to use this in our commercial apps?

    — answered July 1st 2010 by Damien Elmes
    permalink
    1 Comment
    • I think it must be MIT license, because ZipArchive is under MIT. So you may use it in commercial apps.

      — commented July 1st 2010 by Gennadiy Potapov
  • this is great!

    one problem,

    http://github.com/TermiT/ZipFile/blob/master/Classes/ZipFileModule.m#L103

    on line #103 - you should not release the filemanager or you'll get a crasher. the filemanager instance returned is already autoreleased so you don't need to release.

    — answered July 1st 2010 by Jeff Haynie
    permalink
    1 Comment
    • Thanks, Jeff, I'll fix it.

      — commented July 1st 2010 by Gennadiy Potapov
  • ok, I build it and now I got a zipfile…. what now?

    I copied the extracted module folder to /Library/Application Support/Titanium
    but I can't use it…. :-(

    — answered August 5th 2010 by Marc Bender
    permalink
    1 Comment
    • Ok, nevermind… I found it out…

      You'll need to register your module with your application by adding the following to your tiapp.xml file in your application project directory.

      <modules>
      <module version="0.1">mymodule</module>
      </modules>

      — commented August 5th 2010 by Marc Bender
  • ok, I build it and now I got a zipfile…. what now?

    I copied the extracted module folder to /Library/Application Support/Titanium
    but I can't use it…. :-(

    — answered August 5th 2010 by Marc Bender
    permalink
    0 Comments
  • Thanks for sharing - this is quite helpful.
    One quick note/question - my compile time for my app without the Zip module is clocked at 0.8 secs, but with the module it slows to 27 secs. Any idea why it takes so much longer to compile with the module?

    — answered September 1st 2010 by Gary Wong
    permalink
    1 Comment
    • Please see this ticket:

      http://developer.appcelerator.com/question/61611/projects-that-use-modules-always-do-a-full-build

      — commented September 16th 2010 by Damien Elmes
  • Here's an updated version which adds the ability to create zips. Hopefully the poster will merge this when he gets a chance.

    http://github.com/dae/ZipFile/tree/

    — answered September 17th 2010 by Damien Elmes
    permalink
    0 Comments
  • Sweet! This should come in handy for an apps that require file downloads!

    — answered June 30th 2010 by Sj Singh
    permalink
    0 Comments
  • This is fantastic - thank you.

    Are there any plans (or perhaps support, if I'm missing something) on supporting tar or gzip? Standard zip files work fine, however a .gz file throws the following console output –

    [DEBUG] [object ZipFileModule] loaded
    [DEBUG] can't open zip
    [DEBUG] can't open zip
    ...again and again
    
    — answered October 25th 2010 by Kevin McGrath
    permalink
    0 Comments
  • I just came across this module, and it should be perfect for my needs. A few questions:

    • On the downloads at github, the 0.1.18 folder structure is different than the 0.1.17 structure. The .17 is prebuilt with the folders to drop into place per the Readme file. The .18 appears to need to be compiled. For newbies like myself, where / how do you "Just run ./build.py" ?

    • Since .17 is already built, I am trying to use that in a project. In the Ti console window it never gets past "Performing clean build". It says it detected third-party module: zipfile/0.1.17 and the "Performing full rebuild…" then says "Performing clean build" and just appears to hang.

    I have tried using Ti SDK 1.4.2 and 1.5.0 beta.

    I can only get it to do the above if I close Ti, empty the project build/iphone folder, and retry. If I don't do that, it hangs at "iPhone SDK version: 4.1"

    What am I doing wrong that I cannot build even for the emulator?

    — answered November 9th 2010 by Doug Handy
    permalink
    0 Comments
  • does this allow the creation of .zip files as well or just the unzipping of them?

    — answered November 10th 2010 by danno watts
    permalink
    0 Comments
  • It now allows the creation as well. However, notice that it is iOS specific. It does not have a similar android module included.

    — answered November 10th 2010 by Doug Handy
    permalink
    0 Comments
  • It now allows the creation as well. However, notice that it is iOS specific. It does not have a similar android module included.

    — answered November 10th 2010 by Doug Handy
    permalink
    0 Comments
  • Thanks for sharing this - it's something I'd planned to look into in the future. You didn't touch the license file though - are you allowing us to use this in our commercial apps?

    — answered July 1st 2010 by Damien Elmes
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.