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

Unzip plugin for phonegap 2.3 or higher in android?

本文关键字:版本 插件 解压缩 高版本 中的 android phonegap      更新时间:2023-09-26

我正在为android搜索一个phonegap 2.3插件,它可以解压缩文件夹。我在phonegap官方仓库找到了这个插件但它只在phonegap 1.3中工作,而且它只解压了一半的文件,我有一个zip文件夹,里面有50个60 html文件。但它只提取了5到10个文件并返回"IO错误"。请帮我找到PhoneGap 2.3或更高版本的android解压缩插件

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

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

[EDIT](答案已更改)

临时的替代方法是使用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 一起工作