1

我正在寻找一个可以解压文件夹的 android phonegap 2.3 插件。我在 phonegap 官方存储库中找到了这个插件, 但它只在 phonegap 1.3 中工作而且它只解压缩文件的一半我有一个包含 50 60 个 html 文件的 zip 文件夹。但它只提取 5 到 10 个文件并返回 "IO error" 。请帮我找到适用于 PhoneGap 2.3 或更高版本的 android 解压缩插件

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

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

4

1 回答 1

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

于 2013-07-03T04:58:55.480 回答