Unzip plugin for phonegap 2.3 or higher in android?

梦想的初衷 提交于 2019-12-10 11:42:31

问题


I am searching for a phonegap 2.3 plugin for android which can UnZip the folder . I found this plugin at phonegap official repositry but it is working only in phonegap 1.3 And it is unzipping only half of the file i have a zip folder containing 50 60 html files . but it is extracting only 5 to 10 files and returning "IO error" . Please help me finding a unzip plugin of android for PhoneGap 2.3 or higher

I edited this plugin you can also download from

https://github.com/ashishanautiyal/Unzip-PhoneGap--Plugin


回答1:


[EDIT](Answer Changed)

Temporary alternate way to do this is by JavaScript. Here's the code-

var readFile = function(){
    $("#status").html("<br/>");
    var url= $("#urlToLoad").val();
    var doneReading = function(zip){
        extractEntries(zip);
    };

    var zipFile = new ZipFile(url, doneReading);
};


// this function extracts the entries from an instantiated zip
function extractEntries(zip){
    $('#report').accordion('destroy');

    // clear
    $("#report").html('');

    var extractCb = function(id) {
        // this callback is invoked with the entry name, and entry text
        // in my demo, the text is just injected into an accordion panel.
        return (function(entryName, entryText){
            var content = entryText.replace(new RegExp( "\\n", "g" ), "<br/>");
            $("#"+id).html(content);
            $("#status").append("extract cb, entry(" + entryName + ")  id(" + id + ")<br/>");
            $('#report').accordion('destroy');
            $('#report').accordion({collapsible:true, active:false});
        });
    }

    // for each entry in the zip, extract it. 
    for (var i=0; i<zip.entries.length;  i++) {
        var entry = zip.entries[i];

        var entryInfo = "<h4><a>" + entry.name + "</a></h4>\n<div>";

        // contrive an id for the entry, make it unique
        var randomId = "id-"+ Math.floor((Math.random() * 1000000000));

        entryInfo += "<span class='inputDiv'><h4>Content:</h4><span id='" + randomId +
            "'></span></span></div>\n";

        // insert the info for one entry as the last child within the report div
        $("#report").append(entryInfo);

        // extract asynchronously
        entry.extract(extractCb(randomId));
    }
}

Attach this to Click event, also it may take time for large zip files. It works with node.js



来源:https://stackoverflow.com/questions/17439837/unzip-plugin-for-phonegap-2-3-or-higher-in-android

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