javascript - 使用 12mb 文件大小的解压缩时出错

标签 javascript node.js express unzip

我正在使用以下开源解压缩文件并按预期工作 zip 大小为 2-5 MB 但当我将 zip 放在 10 MB 以上时出现错误, 有更稳定的开源可用于大型 zip 文件吗? 我需要它在 MIT 许可下。 这是我用过的 https://github.com/EvanOxfeld/node-unzip

var extractor = unzip.Extract({ path: "../"});

extractor.on("close", function() {
    console.log("Success unzip");
});

extractor.on("close", function(err) {
    console.log(err);
});

req.pipe(extractor);

最佳答案

根据this issue of the unzip github page - https://github.com/EvanOxfeld/node-unzip/issues/73 ,

  • 不再支持解压缩模块。
  • 一个与来自 http 的流相关的问题似乎已经在一个名为 unzip2 的分支中解决了(它也很老了)

试试

npm install unzip2

您还可以尝试其他 zip MIT 模块:

你也可以找到这个库 - https://www.npmjs.com/package/yauzl这就解释了为什么“zip”文件格式不太适合流式传输。

https://www.npmjs.com/package/yauzl#no-streaming-unzip-api

Due to the design of the .zip file format, it's impossible to interpret a .zip file from start to finish (such as from a readable stream) without sacrificing correctness. The Central Directory, which is the authority on the contents of the .zip file, is at the end of a .zip file, not the beginning. A streaming API would need to either buffer the entire .zip file to get to the Central Directory before interpreting anything (defeating the purpose of a streaming interface), or rely on the Local File Headers which are interspersed through the .zip file. However, the Local File Headers are explicitly denounced in the spec as being unreliable copies of the Central Directory, so trusting them would be a violation of the spec.

Any library that offers a streaming unzip API must make one of the above two compromises, which makes the library either dishonest or nonconformant (usually the latter). This library insists on correctness and adherence to the spec, and so does not offer a streaming API.

在 NPM 上有 354 个结果要“解压缩” - https://www.npmjs.com/search?q=unzip

无论您选择什么库,请确保首先使用该库编写一个 node.js 程序,该程序可以直接从文件系统中提取您出错的 zip 文件的内容。

一旦此方法生效,您将能够为 Web 服务器增加额外的复杂性。

关于javascript - 使用 12mb 文件大小的解压缩时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33553797/

相关文章:

node.js - multer,multiparty和connect-multiparty + Nodejs之间的区别

javascript - Event.ClientX 在 firefox 和 chrome 中不工作

javascript - 在 Ubuntu 16 服务器上运行使用 Firebird 的 nodejs 应用程序

mongodb - 如何从 find 方法返回 Mongoose 结果?

javascript - 无法使用 MEAN 堆栈显示图像

javascript - 在 Javascript 中动态调用函数

node.js - 发送到 S3 的 AWS 访问 ID 与我在 Node AWS-SDK 中指定的不同

javascript - 带有 `crossOrigin="匿名 "` can' t 的图像标签从 S3 加载成功

javascript - 了解 Ramda 中转换器的使用

javascript - 如何用嵌套字符串分割字符串