是否有 javascript 库可用于合并 2 个或更多 zip 文件而无需解压缩它们
Is there a javascript library that can be used to merge 2 or more zip files without unzipping them
是否有 javascript 库可用于将 2 个或更多 zip 文件合并为一个新的 zip 文件,而无需先解压缩它们。我一直在寻找,但一直找不到。
我正在添加这个问题,因为我没有得到很好的答案。
首先,这是可能的,并且已经在多种不同语言的库中完成(特别是合并 zip 文件而不先解压缩)。这是由于 zip 格式的工作方式,请阅读它而不是告诉我这是不可能的。
其次,请不要 post 链接到随机 zip 库,我特别需要将两个 zip 文件合并在一起,而不是任何其他与 zip 相关的功能。
最后,我真的不关心解决方案是针对客户端还是服务器端(或者对此主题的个人感受是什么),我只需要在javascript。
提前致谢
几天前,客户端完全不支持文件处理(我的意思是使用 JavaScript),但现在部分支持,但有一些限制。您可以使用 HTML 5 API 阅读 Images/PDFs 等。但我仍然怀疑我们是否可以在客户端执行此类操作(提取或合并 zip 文件)。
我建议在服务器端做这些事情。
Fiddle: https://mikethedj4.github.io/kodeWeave/editor/#ca2d1692722e8f6c321c322cd33ed246
经过几个小时和失败的尝试,我终于让它与 JSZip 一起工作!
JavaScript:
// Set Sample URL
document.getElementById("zipurl").value = "https://mikethedj4.github.io/kodeWeave/editor/zips/font-awesome.zip";
$(".loadzipurl").on("click", function() {
if ( (!document.getElementById("zipurl").value) ) {
// Do nothing
console.error("Unable to perform operation as value is blank!");
} else {
if ( (document.getElementById("zipurl").value.toLowerCase().substring(0,7) === "http://" ) || (document.getElementById("zipurl").value.toLowerCase().substring(0,8) === "https://") ) {
JSZipUtils.getBinaryContent(document.getElementById("zipurl").value, function(error, repoFiles) {
if(error) {
throw error // or handle err
}
var webAppZipBinary = repoFiles;
// Download as Windows App
JSZipUtils.getBinaryContent("https://mikethedj4.github.io/kodeWeave/editor/zips/YourLinApp.zip", function(err, data) {
if(err) {
throw err // or handle err
}
console.log("Creating application!");
var zip = new JSZip();
zip.load(data);
// Your Web Application
zip.folder("HELLOMOMMY/").load(webAppZipBinary);
// For 32bit Windows Application
zip.file("package.json", '{\n "main" : "index.html",\n "name" : "test",\n "window": {\n "toolbar" : false,\n "icon" : "app/icons/128.png",\n "width" : 1000,\n "height" : 600,\n "position": "center"\n }\n}');
zip.file("index.html", '<!doctype html>\n<html>\n <head>\n <title>test</title>\n <style>\n iframe {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n overflow: visible;\n border: 0;\n }\n </style>\n </head>\n <body>\n <iframe src="app/index.html"></iframe>\n </body>\n</html>');
// Export your application
var content = zip.generate({type:"blob"});
saveAs(content, "test-win.zip");
return false;
});
});
} else {
console.error("Error! \"http://\" and \"https://\" urls are only supported!");
}
}
});
HTML:
<input type="text" id="zipurl" placeholder="http://">
<button class="loadzipurl">Export Application</button>
是否有 javascript 库可用于将 2 个或更多 zip 文件合并为一个新的 zip 文件,而无需先解压缩它们。我一直在寻找,但一直找不到。
我正在添加这个问题,因为我没有得到很好的答案。
首先,这是可能的,并且已经在多种不同语言的库中完成(特别是合并 zip 文件而不先解压缩)。这是由于 zip 格式的工作方式,请阅读它而不是告诉我这是不可能的。
其次,请不要 post 链接到随机 zip 库,我特别需要将两个 zip 文件合并在一起,而不是任何其他与 zip 相关的功能。
最后,我真的不关心解决方案是针对客户端还是服务器端(或者对此主题的个人感受是什么),我只需要在javascript。
提前致谢
几天前,客户端完全不支持文件处理(我的意思是使用 JavaScript),但现在部分支持,但有一些限制。您可以使用 HTML 5 API 阅读 Images/PDFs 等。但我仍然怀疑我们是否可以在客户端执行此类操作(提取或合并 zip 文件)。
我建议在服务器端做这些事情。
Fiddle: https://mikethedj4.github.io/kodeWeave/editor/#ca2d1692722e8f6c321c322cd33ed246
经过几个小时和失败的尝试,我终于让它与 JSZip 一起工作!
JavaScript:
// Set Sample URL
document.getElementById("zipurl").value = "https://mikethedj4.github.io/kodeWeave/editor/zips/font-awesome.zip";
$(".loadzipurl").on("click", function() {
if ( (!document.getElementById("zipurl").value) ) {
// Do nothing
console.error("Unable to perform operation as value is blank!");
} else {
if ( (document.getElementById("zipurl").value.toLowerCase().substring(0,7) === "http://" ) || (document.getElementById("zipurl").value.toLowerCase().substring(0,8) === "https://") ) {
JSZipUtils.getBinaryContent(document.getElementById("zipurl").value, function(error, repoFiles) {
if(error) {
throw error // or handle err
}
var webAppZipBinary = repoFiles;
// Download as Windows App
JSZipUtils.getBinaryContent("https://mikethedj4.github.io/kodeWeave/editor/zips/YourLinApp.zip", function(err, data) {
if(err) {
throw err // or handle err
}
console.log("Creating application!");
var zip = new JSZip();
zip.load(data);
// Your Web Application
zip.folder("HELLOMOMMY/").load(webAppZipBinary);
// For 32bit Windows Application
zip.file("package.json", '{\n "main" : "index.html",\n "name" : "test",\n "window": {\n "toolbar" : false,\n "icon" : "app/icons/128.png",\n "width" : 1000,\n "height" : 600,\n "position": "center"\n }\n}');
zip.file("index.html", '<!doctype html>\n<html>\n <head>\n <title>test</title>\n <style>\n iframe {\n position: absolute;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n overflow: visible;\n border: 0;\n }\n </style>\n </head>\n <body>\n <iframe src="app/index.html"></iframe>\n </body>\n</html>');
// Export your application
var content = zip.generate({type:"blob"});
saveAs(content, "test-win.zip");
return false;
});
});
} else {
console.error("Error! \"http://\" and \"https://\" urls are only supported!");
}
}
});
HTML:
<input type="text" id="zipurl" placeholder="http://">
<button class="loadzipurl">Export Application</button>