in lib/common/VersionDownloader.ts [13:40]
private static _downloadFile(url: string, destination: string): Promise<string> {
Logger.info(`Downloading ${url}.`);
return new Promise((resolve, reject) => {
let stream = request(url)
.on('error', reject)
.on('response', response => {
if (response.statusCode === 200) {
stream
.pipe(zlib.createGunzip())
.pipe(tar.extract(destination, {
map: header => {
header.name = header.name.substring(header.name.indexOf('/'));
return header;
}
}))
.on('finish', () => {
resolve(destination);
stream.destroy();
Logger.info(`Downloaded ${url} successfully.`);
});
} else {
reject(`Failed to download ${url}. Status code: ${response.statusCode}.`);
stream.destroy();
}
});
});
}