Unzipping file in phonegap using zip.js

别说谁变了你拦得住时间么 提交于 2019-12-23 20:05:08

问题


am using PhoneGap Cordova 3.3.0 and latest version of zip.js. The script is able to get the list of files inside the archive but is unable to get any binary data. Am using the fix by Hugeen but no luck.

function decompress(fullsavepath, filename){
    zip.useWebWorkers = false;
    file_system.root.getFile("app_cache/temp.zip", {}, function(fileEntry){
        fileEntry.file(function (file) {

            zip.createReader(new zip.BlobReader(file), function(reader) {

                // get all entries from the zip
                reader.getEntries(function(entries) {
                    if (entries.length) {
                        //Output zip file contents
                        for(var i=0; i<entries.length;i++){
                            console.log(entries[i].filename);
                        }

                        //Try to decompress file no. 3
                        console.log('---- entries[2] '+entries[2].filename);
                        entries[2].getData(new zip.BlobWriter(), function(unzipData){
                            console.log(unzipData);
                        },null, null);
                    }
                });
            }, null);

        })

    },null);
}

Here is my console log with the relevant messages:

Console: ----entries[2] photoalbum/bpage1.jpg at file:///android_asset/www/dl/index.html:315
Console: processMessage failed: Message: S01 File821048650 AUEsDBBQAAAAIAEFVCEMFqmCrQAsHAMa3BwASAAAA at file:///android_asset/www/cordova.js:1034
Console: processMessage failed: Error: TypeError: undefined is not a function at file:///android_asset/www/cordova.js:1035
Console: processMessage failed: Stack: TypeError: undefined is not a function
Console:     at inflate (file:///android_asset/www/dl/js/vendor/zip/zip.js:429:18)
Console:     at file:///android_asset/www/dl/js/vendor/zip/zip.js:600:16
Console:     at BlobWriter.init (file:///android_asset/www/dl/js/vendor/zip/zip.js:297:4)
Console:     at file:///android_asset/www/dl/js/vendor/zip/zip.js:596:12
Console:     at [object Object].<anonymous> (file:///android_asset/www/dl/js/vendor/zip/zip.js:203:5)
Console:     at file:///android_asset/www/plugins/org.apache.cordova.core.file/www/FileReader.js:352:20
Console:     at Object.callbackFromNative (file:///android_asset/www/cordova.js:292:54)
Console:     at processMessage (file:///android_asset/www/cordova.js:1029:21)
Console:     at Function.processMessages (file:///android_asset/www/cordova.js:1063:13)
Console:     at pollOnce (file:///android_asset/www/cordova.js:933:17) at file:///android_asset/www/cordova.js:1036

------ UPDATE 2014-04-07 -------------

In the end we used an alternative approach to solve the problem. Google developed a native plugin for Android and iOS - https://github.com/MobileChromeApps/zip

It is quite straight forward, and honestly one of the rare plugins we used that succeeded doing what we needed on first try.

Example:

 zip.unzip("cdvfile://localstorage/downloaded.zip", 
           "cdvfile://localstorage/my_data/path/", 
           function(){
              console.log('Zip decompressed successfully');
           }
 );

PS: Cordova has since been updated to 3.4.0 - My original question used paths like file:///android_asset/www which has all been replaced with the new cdvfile://


回答1:


-- COPIED FROM MY EDIT ABOVE--

In the end we used an alternative approach to solve the problem. Google developed a native plugin for Android and iOS - https://github.com/MobileChromeApps/zip

It is quite straight forward, and honestly one of the rare plugins we used that succeeded doing what we needed on first try.

Example:

 zip.unzip("cdvfile://localstorage/downloaded.zip", 
           "cdvfile://localstorage/my_data/path/", 
           function(){
              console.log('Zip decompressed successfully');
           }
 );

PS: Cordova has since been updated to 3.4.0 - My original question used paths like file:///android_asset/www which has all been replaced with the new cdvfile://



来源:https://stackoverflow.com/questions/21334174/unzipping-file-in-phonegap-using-zip-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!