如何使用 Node.js 解压文件

Mah*_*Ush 3 javascript compression node.js

我需要使用 Node.js 压缩和解压缩文件,但遇到问题。

const fs = require("fs");
const zlib = require('zlib');



function UnZip(zip, paths) {

  var inp = fs.createReadStream("f:/test.zip");

  var Exzip = zlib.createUnzip();

  inp.pipe(Exzip).pipe("f:/");

}
Run Code Online (Sandbox Code Playgroud)

错误:

类型错误:dest.on 不是函数

Cha*_*lie 6

以下是如何使用 zlib 模块来做到这一点。

const fs = require('fs');
const zlib = require('zlib');

const fileContents = fs.createReadStream('file1.txt.gz');
const writeStream = fs.createWriteStream('file1.txt');
const unzip = zlib.createGunzip();

fileContents.pipe(unzip).pipe(writeStream);
Run Code Online (Sandbox Code Playgroud)