mirror of
https://github.com/Mastermindzh/tidal-hifi.git
synced 2024-10-30 01:49:03 +01:00
27 lines
539 B
JavaScript
27 lines
539 B
JavaScript
|
const download = {};
|
||
|
const request = require("request");
|
||
|
const fs = require("fs");
|
||
|
|
||
|
/**
|
||
|
* download and save a file
|
||
|
* @param {*} fileUrl url to download
|
||
|
* @param {*} targetPath path to save it at
|
||
|
*/
|
||
|
download.downloadFile = function(fileUrl, targetPath) {
|
||
|
return new Promise((resolve, reject) => {
|
||
|
var req = request({
|
||
|
method: "GET",
|
||
|
uri: fileUrl,
|
||
|
});
|
||
|
|
||
|
var out = fs.createWriteStream(targetPath);
|
||
|
req.pipe(out);
|
||
|
|
||
|
req.on("end", resolve);
|
||
|
|
||
|
req.on("error", reject);
|
||
|
});
|
||
|
};
|
||
|
|
||
|
module.exports = download;
|