【问题标题】:Is there a javascript library that can be used to merge 2 or more zip files without unzipping them是否有一个 javascript 库可用于合并 2 个或多个 zip 文件而无需解压缩它们
【发布时间】:2015-10-05 12:08:07
【问题描述】:

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


我正在添加这个问题,因为我没有得到很好的答案。

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

其次,请不要发布指向随机 zip 库的链接,我特别需要将两个 zip 文件合并在一起,而不是任何其他与 zip 相关的功能。

最后,我并不关心解决方案是针对客户端还是服务器端(或者个人对此主题的感受是什么),我只需要在 javascript 中完成。

提前谢谢你

【问题讨论】:

  • 不,这是不可能的。您可以使用两者创建一个新的第三个 zip。
  • :mike 我已经看到了,它无法在不解压缩的情况下合并 zip 文件。 :dandavis,你能否解释一下为什么你说这是不可能的,因为我已经看到许多库能够做到这一点,如果需要,我可以向你解释它在技术上是如何实现的。

标签: javascript file zip


【解决方案1】:

小提琴: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>

【讨论】:

  • 哇 3 年后,有一个“官方解决方案”。我最初只是通过使用数组缓冲区手动操作 zip 文件内容来解决我的问题。很高兴看到终于有一个图书馆可以做到这一点。
【解决方案2】:

几天前,客户端(我的意思是使用 JavaScript)完全不支持文件处理,但现在这部分支持,但有一些限制。您可以使用 HTML 5 API 在此帮助下阅读图像/PDF 等。但我仍然怀疑我们是否可以在客户端执行此类操作(提取或合并 zip 文件)。

我建议在服务器端做这些事情。

【讨论】:

  • 感谢它的功能非常有用,不幸的是它不支持合并 zip 文件 nativley
猜你喜欢
  • 2010-09-21
  • 1970-01-01
  • 1970-01-01
  • 2022-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-25
相关资源
最近更新 更多