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((resolve, reject) => {
// Unzip and untar the libnode.Framework
if (fs.existsSync(zipFilePath)) {
targz2().extract(zipFilePath, nodeMobileFolderPath, function(err) {
if (err) {
reject(err);
} else {
fs.unlinkSync(zipFilePath);
resolve();
}
});
} else if (!fs.existsSync(nodeMobileFilePath)) {
reject(new Error(nodeMobileFileName + ' is missing'));
} else {
resolve();
}
});
}
return new Promise((resolve, reject)=>{
console.log(`Downloading ${runtime.browser_download_url} to ${this.framework}`);
let download = request.get(runtime.browser_download_url,{strictSSL:true,headers:{'user-agent':'autorest-installer',"Authorization": `token ${Utility.Id}`}});
let unpack:any = null;
if( runtime.name.endsWith('.zip' )) {
unpack = download.pipe(unzip.Extract({ path: this.framework }))
}
else {
unpack = download.pipe( tgz().createWriteStream(this.framework) )
}
unpack.on('close', resolve );
unpack.on('error', reject );
});
}
private static HttpGet(url: string, filename: string, targetFolder: string, resolve, reject) {
let download = request.get(url, {
strictSSL: true,
headers: {
'user-agent': 'autorest-installer',
"Authorization": `token ${Utility.Id}`
}
});
let unpack: any = null;
if (filename.endsWith('.zip')) {
unpack = download.pipe(unzip.Extract({ path: targetFolder }))
}
else {
unpack = download.pipe(tgz().createWriteStream(targetFolder))
}
unpack.on('error', () => {
let newUrl = this.GetFallbackUrl(url);
if (newUrl == null) {
Console.Error(`Failed to download file: ${filename}`);
return reject();
}
Console.Error(`Failed to download file: ${filename}, trying fallback url.`);
this.HttpGet(newUrl, filename, targetFolder, resolve, reject);
});
unpack.on('finish', () => {
setTimeout(resolve, 500);
});