无法使用 zlib 模块解压缩压缩文件

Unable to unzip the zipped files using zlib module

我正在尝试使用节点内置模块 zlib 从压缩数据中解压缩文件,由于某种原因我无法解压缩它,我收到如下错误:

Error: incorrect header check
test.js:53
No debug adapter, can not send 'variables'

我正在尝试的代码如下:

var zlib = require('zlib');
var fs = require('fs');
var filename = './Divvy_Trips_2019_Q2.zip';

var str1 = fs.createReadStream(filename);

var gzip = zlib.createGunzip();

str1.pipe(gzip).on('data', function (data) {
    console.log(data.toString());
}).on('error', function (err) {
    console.log(err);
});

压缩后的URL数据如下:Divvy_Trips_2019_Q2.zip

GZip (.gz) 和 ZIP (.zip) 是不同的格式。您需要一个处理 ZIP 文件的库,例如 yauzl.

// https://github.com/thejoshwolfe/yauzl/blob/master/examples/dump.js

const yauzl = require("yauzl");

const path = "./Divvy_Trips_2019_Q2.zip";

yauzl.open(path, function(err, zipfile) {
  if (err) throw err;
  zipfile.on("error", function(err) {
    throw err;
  });
  zipfile.on("entry", function(entry) {
    console.log(entry);
    console.log(entry.getLastModDate());
    if (/\/$/.exec(entry)) return;
    zipfile.openReadStream(entry, function(err, readStream) {
      if (err) throw err;
      readStream.pipe(process.stdout);
    });
  });
});