【备忘录】node创建加密(解压密码)的压缩文件

const fs = require('fs');
const archiver = require('archiver');
const encrypted = require('archiver-zip-encrypted');
archiver.registerFormat('zip-encrypted', encrypted);
const outPath = './test.zip';
const out = fs.createWriteStream(outPath);
const archive = archiver.create('zip-encrypted', {
  zlib: {
    level: 8
  },
  encryptionMethod: 'aes256',
  password: '123'
});
// 压缩文件
// archive.file('./app.js');
// 压缩文件夹
archive.directory('./test', false);
archive.pipe(out);

out.on('close', () => {
  console.log('压缩完成', archive.pointer() / 1024 / 1024 + 'M');
});
archive.on('error', err => {
  console.log('压缩失败!');
  throw err;
});
// 打包  promise函数
archive.finalize();

你可能感兴趣的:(【备忘录】node创建加密(解压密码)的压缩文件)