我正在使用JSZip打开一个zip文件。使用npapi-file-io插件将每个文件循环并保存为二进制文件。问题是;这很慢。即使是2mb的zip文件,在本地提取zip也需要几分钟。如果我将文件保存为文本文件,速度非常快。但是它们必须保存为二进制或者它们会变得腐败。有任何想法吗?请告诉我,我做错了这个或者做得不好。
//read contents of zip file
var zip = new JSZip(e.target.result);
$.each(zip.files, function (index, zipEntry) {
var filename = zipEntry.name;
//create directory else create file
var path = getPath(filename);
if (filename.match(/\/$/)) {
//plugin is the embeded npapi-file-io plugin
plugin.createDirectory(path);
} else {
//problem is here
plugin.saveBinaryFile(path, zipEntry.asUint8Array());
//this is faster and works with the txt files but not images ect.
//plugin.saveTextFile(path, zipEntry.data);
}
答案 0 :(得分:1)
没有高效的方法将二进制数据发送到插件;基本上使用uint8array发送内容总是非常慢,因为npapi的工作方式,所以如果你能发送base64编码你会更好。归结起来,以高效的方式真正做到这一点的唯一方法就是创建自己的插件。