1 | import fs from "node:fs";
|
2 | import stream from "node:stream";
|
3 |
|
4 | import axios from "axios";
|
5 |
|
6 | /**
|
7 | * Download from `url`.
|
8 | *
|
9 | * @async
|
10 | * @function
|
11 | *
|
12 | * @param {string} url - Download server
|
13 | * @param {string} filePath - file path of downloaded content
|
14 | * @return {Promise<void>}
|
15 | */
|
16 | export default async function request(url, filePath) {
|
17 |
|
18 | const writeStream = fs.createWriteStream(filePath);
|
19 |
|
20 | const response = await axios({
|
21 | method: "get",
|
22 | url: url,
|
23 | responseType: "stream"
|
24 | });
|
25 |
|
26 | await stream.promises.pipeline(response.data, writeStream);
|
27 | }
|