最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

使用 jszip 读取块

网站源码admin33浏览0评论

使用 jszip 读取块

使用 jszip 读取块

我找不到从 HTTP 响应中将 zip 内容作为块读取的方法。

我提供了一个 JSZip 库的示例。(如有必要,我对其他库开放)

const zip = new JSZip();

const readZipCunk = async (chunk)=>{
     const ziped = await zip.loadAsync(chunk, { optimizedBinaryString: true })
     ziped.forEach((relativePath, file) => {
            file.nodeStream().pipe(parser); // parser is not relevant , just demonstrate 
                                           //what i do with the "extracted" chunk
     });
}

https.get(options, (res) => {
     res.on("data",readZipCunk );
 })

当 zip 文件较小时,它可能会成功,但当文件大时,我会出错。 错误:zip 损坏:找不到中央目录的末尾

ofc,如果我将连接块并在以下位置调用“readZipCunk”函数:

response.on('data',(chunk)=>{chunks.push(chunk})
response.on('end',()=>{readZipCunk( Buffer.concat(chunks)}) // it will work

但我必须尽可能保持低内存,我也知道 zip 文件的一些信息,如文件名、大小,也许我可以使用这些信息并避免使用请求中央目录?

回答如下:

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论