import * as fs from "fs"; import axios from "axios"; export type HttpHeaders = { [name: string]: string }; export async function get(url: string, headers?: HttpHeaders): Promise { const response = await axios.get(url, { responseType: "text", headers }); return response.data; } export async function download(url: string, file: string, headers?: HttpHeaders): Promise { const response = await axios(url, { responseType: "stream", headers }); const stream = response.data.pipe(fs.createWriteStream(file)); return new Promise((resolve, reject) => { stream.on("finish", resolve); stream.on("error", reject); }); }