解压缩android中的phonegap 2.3或更高版本的插件?

时间:2013-07-03 04:44:39

标签: javascript android cordova phonegap-plugins

我正在为android搜索一个可以解压缩文件夹的phonegap 2.3插件。我找到了this plugin at phonegap official repositry 但它只在phonegap 1.3中工作它只解压缩文件的一半我有一个包含50个60 html文件的zip文件夹。但它只提取5到10个文件并返回“IO错误”。请帮我找到适用于PhoneGap 2.3或更高版本的Android解压缩插件

我编辑了这个插件,你也可以从

下载

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

1 个答案:

答案 0 :(得分:3)

[编辑](答案已更改)

执行此操作的临时替代方法是使用JavaScript。 这是代码 -

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));
    }
}

将此附加到Click事件,大型zip文件也可能需要一些时间。 它适用于node.js