Files
zy-client-a/t_etc_temp2/zip.js
telangpu c73ff3b77a update
2026-04-29 12:37:13 +08:00

40 lines
930 B
JavaScript

const fs = require("fs");
const archiver = require("archiver");
// 创建一个输出流到指定的 zip 文件
const output = fs.createWriteStream(__dirname + "/../../zip/t_etc_temp2.zip"); // 这里可以更改为你想要的文件名
const archive = archiver("zip", {
zlib: { level: 9 }, // 设置压缩级别
});
// 监听关闭事件,打印压缩完成信息
output.on("close", function () {
console.log(archive.pointer() + " total bytes");
console.log(
"archiver has been finalized and the output file descriptor has closed."
);
});
// 捕获警告
archive.on("warning", function (err) {
if (err.code === "ENOENT") {
// log warning
} else {
throw err;
}
});
// 捕获错误
archive.on("error", function (err) {
throw err;
});
// 将输出流管道到归档文件
archive.pipe(output);
// 添加目录到归档文件
archive.directory("dist/", false);
// 完成归档
archive.finalize();