Node.js read a file in a zip without unzipping it

后端 未结 2 910
挽巷
挽巷 2021-02-04 05:16

I have a zip file (actually it\'s an epub file) I need to loop through the files in it and read them without unzipping them to the disk.

I tried to use a Node.js library

2条回答
  •  悲&欢浪女
    2021-02-04 05:53

    npm install unzip
    

    https://www.npmjs.com/package/unzip

        fs.createReadStream('path/to/archive.zip')
      .pipe(unzip.Parse())
      .on('entry', function (entry) {
        var fileName = entry.path;
        var type = entry.type; // 'Directory' or 'File' 
        var size = entry.size;
        if (fileName === "this IS the file I'm looking for") {
          entry.pipe(fs.createWriteStream('output/path'));
        } else {
          entry.autodrain();
        }
      });
    

提交回复
热议问题