NestJS:NodeJS 子进程:解压缩

编程入门 行业动态 更新时间:2024-10-08 04:25:41

NestJS:NodeJS 子进程:<a href=https://www.elefans.com/category/jswz/34/1765540.html style=解压缩"/>

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 子进程:解压缩

本文发布于:2024-05-30 08:49:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770316.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:解压缩   进程   NestJS   NodeJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!