Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((res, rej) => {
const fileName = getCompilerFilename(version)
console.log(`Downloading ${fileName}...`)
const request = require('request')
const progress = require('request-progress')
const { Bar, Presets } = require('cli-progress')
const url = `${DOWNLOAD_URL}/${version}/${fileName}`
const filePath = path.resolve(qconfig.getSolcCachePath(), fileName)
const progressBar = new Bar({}, Presets.shades_classic)
progressBar.start(100, 0)
const fileRequest = progress(request(url), {
throttle: 500,
}).on('progress', state => {
progressBar.update(parseInt(state.percent * 100, 10))
})
.on('response', response => {
if (response.statusCode === 200) {
const fileStream = createWriteStream(filePath)
.on('finish', () => {
fileStream.close(() => {
res(filePath)
})
})
async ReadFiles(files: FileSystemInstance[]): Promise {
let readBar: Bar = new Bar({}, Presets.shades_classic);
let readCounter: number = 0;
readBar.start(files.length, readCounter);
let promises: Promise[] = [];
files.Each((f: FileSystemInstance) => promises.push(this.fileFactory.ReadFile(f, function () {
readCounter++;
readBar.update(readCounter);
if (readCounter >= readBar.getTotal()) {
readBar.stop();
}
})));
return await Promise.all(promises);
}