解压缩"/>
NestJS:NodeJS 子进程:解压缩
我有一个压缩和加密文件的系统:
let output = createWriteStream(`${uploadDest}/${data.name}.zip`);
let archive = archiver.create('zip-encrypted', { zlib: { level: 8 }, encryptionMethod: 'aes256', password: process.env.FILE_ENCRIPTION_KEY });
let file = readFileSync(`${uploadDest}/${data.name}.${data.format}`);
output.on('close', () => {
rmSync(`${uploadDest}/${data.name}.${data.format}`)
console.log('Archive finished.');
this.server.to(`${data.userid}-${data.chatid}-${data.date}`).emit('fileUploadFinished')
});
archive.on('error', (err) => {
throw err;
});
//Step 4 - pipe and append files
archive.pipe(output);
archive.append(file, { name: `${data.name}.${data.format}` });
//Step 5 - finalize
archive.finalize();
它有效(在 OS 中测试),但是当我尝试解压缩它时(我知道 nodejs 子进程是解压缩加密和压缩的 ZIP 文件的唯一方法),但是当我将“解压缩”文件发送到用户,那么它的大小是0 Byte.
if(req.originalUrl.substr(req.originalUrl.length-3, req.originalUrl.length) == "zip"){
var deFile = spawn('unzip', [ '-P',process.env.FILE_ENCRIPTION_KEY, '-d', `./CDN/${req.originalUrl.substr(6, req.originalUrl.length)}` ])
deFile.stdout.on('data', function(data){
console.log(data)
return new StreamableFile(data);
});
}else{
let file: any = readFileSync(`./CDN/${req.originalUrl.substr(6, req.originalUrl.length)}`);
return new StreamableFile(file);
}
有什么建议吗?谢谢!
回答如下:更多推荐
NestJS:NodeJS 子进程:解压缩
发布评论