【脚本】创建可写流下载文件

使用axios请求文件数据指定responseType

1
2
3
4
5
6
7
8
9
10
11
12
13
14
const fs = require("node:fs");
const path = require("node:path");
const axios = require("axios");

const savePath = path.resolve(__dirname)
const writeStream = fs.createWriteStream(savePath);

axios({
url: "https://xxxxxxxxx",
method: "GET",
    responseType: "stream",
}).then((res) => {
res.data.pipe(writeStream)
})