export async function downloadFile()

in vscode/qodana/src/core/report/index.ts [79:109]


export async function downloadFile(url: string, filePath: string): Promise<string | undefined> {
    const response = await axios({
        url,
        method: 'GET',
        responseType: 'stream',
    });
    const writer = fs.createWriteStream(filePath);
    const totalBytes = parseInt(response.headers['content-length']);

    let receivedBytes = 0;

    return vscode.window.withProgress({
        location: vscode.ProgressLocation.Notification,
        title: 'Downloading File',
        cancellable: false
    }, (progress) => {
        // The event 'data' will be emitted when there is data available.
        response.data.on('data', (chunk: any) => {
            receivedBytes += chunk.length;
            let percentage = Math.floor((receivedBytes / totalBytes) * 100).toString() + '%';
            progress.report({ message: percentage });
        });

        response.data.pipe(writer);

        return new Promise((resolve, reject) => {
            writer.on('finish', () => { resolve(filePath); });
            writer.on('error', reject);
        });
    });
}