nodejs: 几个 unzip 库

几个关于解压的库
更新于: 2024-08-10 13:49:14

cheatsheet

名称基本用法
unzipper
import unzipper from 'unzipper';;
import fs from 'fs';

fs.createReadStream('download.zip').pipe(unzipper.Extract({ path: 'output/path' }));
extract-zip
import unzip from 'extract-zip';

const target = process.cwd() + '/dist';

unzip('./download.zip', {
  dir: target,
});
zip-lib
const zl = require("zip-lib");

const unzip = new zl.Unzip({
    // Called before an item is extracted.
    onEntry: function (event) {
        if (/^__MACOSX\//.test(event.entryName)) {
            // entry name starts with __MACOSX/
            event.preventDefault();
        }
    }
})
unzip.extract("path/to/target.zip", "path/to/target").then(function () {
    console.log("done");
}, function (err) {
    console.log(err);
});