mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2025-09-19 10:09:28 +02:00
transitioning to ts
This commit is contained in:
23
src/scripts/download.ts
Normal file
23
src/scripts/download.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
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);
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user