function downloadTool(url, dest) {
    return __awaiter(this, void 0, void 0, function* () {
        // Wrap in a promise so that we can resolve from within stream callbacks
        return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
            try {
                const http = new httpm.HttpClient(userAgent, [], {
                    allowRetries: true,
                    maxRetries: 3
                });
                dest = dest || path.join(tempDirectory, uuidV4());
                yield io.mkdirP(path.dirname(dest));
                core.debug(`Downloading ${url}`);
                core.debug(`Downloading ${dest}`);
                if (fs.existsSync(dest)) {
                    throw new Error(`Destination file path ${dest} already exists`);
                }
                const response = yield http.get(url);
                if (response.message.statusCode !== 200) {
                    const err = new HTTPError(response.message.statusCode);
                    core.debug(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
                    throw err;
                }
                const file = fs.createWriteStream(dest);
                file.on('open', () => __awaiter(this, void 0, void 0, function* () {
                    try {
                        const stream = response.message.pipe(file);
                        stream.on('close', () => {
                            core.debug('download complete');
                            resolve(dest);
                        });
                    }
                    catch (err) {
                        core.debug(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
                        reject(err);
                    }
                }));
                file.on('error', err => {
                    file.end();
                    reject(err);
                });
            }
            catch (err) {
                reject(err);
            }
        }));
    });
}
/**
 * Download a tool from an url and stream it into a file
 *
 * @param url       url of tool to download
 * @param dest      path to download tool
 * @returns         path to downloaded tool
 */
Download a tool from an url and stream it into a file
@param url       url of tool to download
@param dest      path to download tool
@returns         path to downloaded tool
Download a tool from an url and stream it into a file @param url url of tool to download @param dest path to download tool @returns path to downloaded tool
function downloadTool(url, dest) {
    return __awaiter(this, void 0, void 0, function* () {
        return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
            try {
                const http = new httpm.HttpClient(userAgent, [], {
                    allowRetries: true,
                    maxRetries: 3
                });
                dest = dest || path.join(tempDirectory, uuidV4());
                yield io.mkdirP(path.dirname(dest));
                core.debug(`Downloading ${url}`);
                core.debug(`Downloading ${dest}`);
                if (fs.existsSync(dest)) {
                    throw new Error(`Destination file path ${dest} already exists`);
                }
                const response = yield http.get(url);
                if (response.message.statusCode !== 200) {
                    const err = new HTTPError(response.message.statusCode);
                    core.debug(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
                    throw err;
                }
                const file = fs.createWriteStream(dest);
                file.on('open', () => __awaiter(this, void 0, void 0, function* () {
                    try {
                        const stream = response.message.pipe(file);
                        stream.on('close', () => {
                            core.debug('download complete');
                            resolve(dest);
                        });
                    }
                    catch (err) {
                        core.debug(`Failed to download from "${url}". Code(${response.message.statusCode}) Message(${response.message.statusMessage})`);
                        reject(err);
                    }
                }));
                file.on('error', err => {
                    file.end();
                    reject(err);
                });
            }
            catch (err) {
                reject(err);
            }
        }));
    });
}
function downloadTool ( url , dest ) { return __awaiter ( this , void 0 , void 0 , function * ( ) { return new Promise ( ( resolve , reject ) => __awaiter ( this , void 0 , void 0 , function * ( ) { try { const http = new httpm . HttpClient ( userAgent , [ ] , { allowRetries : true , maxRetries : 3 } ) ; dest = dest || path . join ( tempDirectory , uuidV4 ( ) ) ; yield io . mkdirP ( path . dirname ( dest ) ) ; core . debug ( ` ${ url } ` ) ; core . debug ( ` ${ dest } ` ) ; if ( fs . existsSync ( dest ) ) { throw new Error ( ` ${ dest } ` ) ; } const response = yield http . get ( url ) ; if ( response . message . statusCode !== 200 ) { const err = new HTTPError ( response . message . statusCode ) ; core . debug ( ` ${ url } ${ response . message . statusCode } ${ response . message . statusMessage } ` ) ; throw err ; } const file = fs . createWriteStream ( dest ) ; file . on ( 'open' , ( ) => __awaiter ( this , void 0 , void 0 , function * ( ) { try { const stream = response . message . pipe ( file ) ; stream . on ( 'close' , ( ) => { core . debug ( 'download complete' ) ; resolve ( dest ) ; } ) ; } catch ( err ) { core . debug ( ` ${ url } ${ response . message . statusCode } ${ response . message . statusMessage } ` ) ; reject ( err ) ; } } ) ) ; file . on ( 'error' , err => { file . end ( ) ; reject ( err ) ; } ) ; } catch ( err ) { reject ( err ) ; } } ) ) ; } ) ; }
Download a tool from an url and stream it into a file
 @param url       url of tool to download
 @param dest      path to download tool
 @returns         path to downloaded tool
Download a tool from an url and stream it into a file @param url url of tool to download @param dest path to download tool @returns path to downloaded tool
// Wrap in a promise so that we can resolve from within stream callbacks