簡體   English   中英

解壓zip文件並排除NodeJS中的根目錄

[英]Unzip the zip file and exclude the root directory in NodeJS

是否有任何庫可以在解壓縮時排除根目錄。

例如zip文件包含-根目錄-第一個文件-第二個文件-第三個文件

我想排除根目錄。

我建議使用解壓縮包。

只需提取您要查找的內容:

const unzipper = require('unzipper');
const fs = require('fs');

fs.createReadStream('path/to/archive.zip') // Your zip file
  .pipe(unzipper.Parse())
  .on('entry', function (entry) {
    const fileName = entry.path;
    const type = entry.type; // 'Directory' or 'File'
    // file_name1, file_name1 are files which you are looking for
    if (type === 'File' && ['file_name1', 'file_name1'].indexOf(fileName) >= 0) {
      entry.pipe(fs.createWriteStream('output/path/' + fileName)); // Output folder of unzip process
    } else {
      entry.autodrain();
    }
  });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM