Link to home
Start Free TrialLog in
Avatar of sgotte
sgotte

asked on

How to download and unzip a zip file on iPad using Phonegap and Zip.js

Hello,
I'm trying to unzip a zip file on ipad that's been downloaded onto the device.  The app itself is build using Phonegap javascript code.  I'm trying to do this using zip.js in combination with FileWriter. The code I have so far is included in the attached file.

Here's the list of console messages that appear on Safari Debug:

Log -  successfully downloaded
Log -  Got the zip file from device storage
Log -  zip reader created
Log -  Got the entries
Log -  Outer: pdf
Log -  Outer: jpg
Log -  js/inflate.js
Log -  Got data from the entries
Log -  Got new file to create
Log -  Inner: jpg
Log -  Write completed.
Log -  Got data from the entries
Log -  Got new file to create  
Log -  Inner: jpg
Log -  Write completed.
Log -  Got data from the entries
Log -  Got new file to create  
Log -  Inner: jpg
Log -  Write completed.

In the above unzipping case, there were in fact 3 files in the zip file and the filenames from entries(i).filename were recorded correctly in Sqlite.  However, there were 2 pdfs and 1 jpeg file in the zip I'm currently trying  to extract, but according to the above console output, it seems there's some synchronicity issue with the way I've written this code since it's trying to extract 3 jpegs it appears.  Also, when I try to view any of the downloaded/unzipped files on the device, the console reports:
TypeError: 'undefined' is not an object (evaluating 'event.url')
TypeError: 'undefined' is not an object (evaluating 'event.type')

So there appears to be an issue with the blob of data from the extracted files that is used in the writer.

Has anyone used zip.js successfully in combination with FileWriter to unzip a file onto an ipad device.  For reference, the zip.js I'm referring to is from here: http://gildas-lormeau.github.io/zip.js/

I also tried using chromeutils zip functionality which some people have reported having success with to unzip files on devices, but my app is specifically for iPad, so it seems I can't use that.

If you know of any other way to extract the downloaded zip file onto an iPad device, I am also all ears.

Thank you for your assistance.
ASKER CERTIFIED SOLUTION
Avatar of sgotte
sgotte

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial