首页 > 解决方案 > yauzl中无效的本地文件头签名错误

问题描述

我正在开发一个解压缩功能,它需要从远程目标读取 zip 文件,解压缩内容,然后通过网络将这些文件创建到目标。我正在使用 yauzl 和 RandomAccessReader 方法来读取传入流和发布事件。

const zipQueue = [];

const yauzl = new Yauzl(reader);
const zipfile = yauzl.fromRandomAccessReader(this, this.contentLength, { lazyEntries: true, autoclose: false});
zipfile.on('entry', function(entry){
  zipQueue.push(entry);
  zipfile.readEntry();
  
}).on('end', function() {

  for(const entry of zipQueue) {
   if(/\/$/.test(entry.fileName)) {
    this.emit('directory');
   } else {
     const readStream = zipfile.openReadStream(entry);
     this.emit('file');
   }
 }
})

我正在以正确的格式获取 zipfile 和条目对象,但是当我尝试打开 readStream 时,它在 30 个奇数条目后zipfile.openReadStream()失败。invalid local file header signature: 0x8074b50我怀疑这与比赛条件有关。有没有其他提供类似解决方案的 npm 包?

标签: javascriptzipunzip

解决方案


推荐阅读