mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-06-26 17:54:17 +02:00
24 lines
515 B
TypeScript
24 lines
515 B
TypeScript
import fs from "fs";
|
|
import request from "request";
|
|
|
|
/**
|
|
* download and save a file
|
|
* @param {string} fileUrl url to download
|
|
* @param {string} targetPath path to save it at
|
|
*/
|
|
export const downloadFile = function (fileUrl: string, targetPath: string) {
|
|
return new Promise((resolve, reject) => {
|
|
const req = request({
|
|
method: "GET",
|
|
uri: fileUrl,
|
|
});
|
|
|
|
const out = fs.createWriteStream(targetPath);
|
|
req.pipe(out);
|
|
|
|
req.on("end", resolve);
|
|
|
|
req.on("error", reject);
|
|
});
|
|
};
|