src/http/download.js
/**
 * Download file
 * @param url The URL of the file
 * @param name The name used to identify the file
 * @param extension The file extension (eg. ".jpg" or ".mp4")
 */
Download file
@param url The URL of the file
@param name The name used to identify the file
@param extension The file extension
Download file @param url The URL of the file @param name The name used to identify the file @param extension The file extension
async function download(url, name, extension) {
    mkdirp.sync(this.directory);
    try {
        const response = await axios_1.default({
            method: "get",
            responseType: "stream",
            url,
        });
        await new Promise(async (resolve) => {
            const stream = fs.createWriteStream(this.directory + "/" + name + "." + extension);
            response.data.pipe(stream);
            stream.on("finish", resolve);
        });
    }
    catch (e) {
        this.logger.info(`Downloading ${url} failed`);
        this.logger.debug(e);
    }
}
async function download ( url , name , extension ) { mkdirp . sync ( this . directory ) ; try { const response = await axios_1 . default ( { method : "get" , responseType : "stream" , url , } ) ; await new Promise ( async ( resolve ) => { const stream = fs . createWriteStream ( this . directory + "/" + name + "." + extension ) ; response . data . pipe ( stream ) ; stream . on ( "finish" , resolve ) ; } ) ; } catch ( e ) { this . logger . info ( ` ${ url } ` ) ; this . logger . debug ( e ) ; } }
Download file
 @param url The URL of the file
 @param name The name used to identify the file
 @param extension The file extension (eg.
Download file @param url The URL of the file @param name The name used to identify the file @param extension The file extension ( eg .
// Get data // Write to file // noinspection TypeScriptValidateJSTypes