我想知道是否可以使用Node标准库中的https.get()来下载一个压缩包并将其直接解压缩到一个子文件夹中.
我找到了很多解决方案,都是先下载压缩包,然后再解压缩.但有没有办法直接做到这一点呢?
这是我的try :
const zlib = require("node:zlib");
const fs = require("fs");
const { pipeline } = require("node:stream");
const https = require("https");
const DOWNLOAD_URL =
"https://downloadserver.com/data.zip";
const unzip = zlib.createUnzip();
const output = fs.createWriteStream("folderToExtract");
https.get(DOWNLOAD_URL, (res) => {
pipeline(res, unzip, output, (error) => {
if (error) console.log(error);
});
});
但我得到了这样的错误:
Error: incorrect header check
at Zlib.zlibOnError [as onerror] (node:zlib:189:17) {
errno: -3,
code: 'Z_DATA_ERROR'
}
我很好奇,这有可能吗?