是否有一个javascript库可以用来合并2个或多个zip文件而无需解压缩

是否有一个javascript库可以用来合并2个或多个zip文件而无需解压缩,javascript,file,zip,Javascript,File,Zip,是否有一个javascript库可以用来将2个或多个zip文件合并到一个新的zip文件中,而无需先解压缩它们。我一直在找,但没找到 我补充这个问题,因为我没有得到很好的答案 首先,这是可能的,并且已经在几种不同语言的库中完成(特别是合并zip文件而不首先提取它们)。这是由于zip格式的工作方式,请去阅读它,而不是告诉我这是不可能的 其次,请不要张贴链接到随机压缩库,我特别需要合并两个压缩文件在一起,而不是任何其他压缩相关的功能 最后,我真的不在乎解决方案是针对客户端还是服务器端(或者关于这个主

是否有一个javascript库可以用来将2个或多个zip文件合并到一个新的zip文件中,而无需先解压缩它们。我一直在找,但没找到


我补充这个问题,因为我没有得到很好的答案

首先,这是可能的,并且已经在几种不同语言的库中完成(特别是合并zip文件而不首先提取它们)。这是由于zip格式的工作方式,请去阅读它,而不是告诉我这是不可能的

其次,请不要张贴链接到随机压缩库,我特别需要合并两个压缩文件在一起,而不是任何其他压缩相关的功能

最后,我真的不在乎解决方案是针对客户端还是服务器端(或者关于这个主题的个人感受是什么),我只需要用javascript就可以了


提前感谢

几天前,客户端(我指的是使用JavaScript)完全不支持文件处理,但现在这部分受到了一些限制。您可以使用HTML5API阅读图像/PDF等。但我仍然怀疑我们是否可以在客户端执行这样的操作(提取或合并zip文件)

我建议在服务器端执行这些操作。

Fiddle:

经过几个小时的尝试和失败,我终于让它工作了

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!");
    }
  }
});
<input type="text" id="zipurl" placeholder="http://">
<button class="loadzipurl">Export Application</button>
//设置示例URL
document.getElementById(“zipurl”)。值=“https://mikethedj4.github.io/kodeWeave/editor/zips/font-awesome.zip";
$(.loadzipurl”)。在(“单击”,函数(){
if((!document.getElementById(“zipurl”).value)){
//无所事事
控制台。错误(“值为空,无法执行操作!”);
}否则{
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,函数(error,repotfiles){
如果(错误){
抛出错误//或句柄错误
}
var webAppZipBinary=repoFiles;
//作为Windows应用程序下载
JSZipUtils.getBinaryContent(“https://mikethedj4.github.io/kodeWeave/editor/zips/YourLinApp.zip,函数(错误,数据){
如果(错误){
抛出错误//或处理错误
}
log(“创建应用程序!”);
var zip=newjszip();
zip.load(数据);
//您的Web应用程序
zip.folder(“hellommy/”).load(webAppZipBinary);
//适用于32位Windows应用程序
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”,'\n\n\n test\n\n iframe{\n位置:绝对;\n顶部:0;\n左侧:0;\n宽度:100%;\n高度:100%;\n溢出:可见;\n边框:0;\n}\n\n\n\n\n');
//导出应用程序
var content=zip.generate({type:“blob”});
saveAs(内容为“test win.zip”);
返回false;
});
});
}否则{
错误(“错误!\“http://\”和\“https://\”URL仅受支持!”);
}
}
});
HTML

// 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!");
    }
  }
});
<input type="text" id="zipurl" placeholder="http://">
<button class="loadzipurl">Export Application</button>

出口申请

您看到了吗?不,这是不可能的。您可以使用这两种方法创建新的第三个zip文件。:mike我已经看到,如果不解压缩zip文件,它将无法合并这些文件。:dandavis,你能解释一下为什么你说这是不可能的,因为我已经看到很多图书馆能够做到这一点,如果需要的话,我可以向你解释技术上是如何可能的。谢谢你的这项工作,它所做的非常好,不幸的是,它不支持合并压缩文件nativleywow 3年后,有一个“官方解决方案”。我最初只是通过使用数组缓冲区手动操作zip文件内容来解决我的问题。很高兴看到终于有一个图书馆可以做到这一点。