1
0
silverbullet/desktop/http_util.ts
Zef Hemel fdc08d893a
PoC Electron app (#264)
Initial version of Electron wrapper + build pipeline
2023-01-03 20:46:52 +01:00

30 lines
604 B
TypeScript

import axios from "axios";
import fs from "node:fs";
export async function downloadFile(
url: string,
destFile: string,
): Promise<void> {
const file = fs.createWriteStream(destFile);
let response = await axios.request({
url: url,
method: "GET",
responseType: "stream",
});
return new Promise((resolve, reject) => {
response.data.pipe(file);
let error: Error | null = null;
file.on("error", (e) => {
error = e;
reject(e);
});
file.on("close", () => {
if (error) {
return;
}
file.close();
resolve();
});
});
}