我正在使用以下开源解压缩文件并按预期工作 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/