scripts/resources.js
async function downloadAndUnpackResource(uri, destPath, callback) {
  // If HTTPS_PROXY, https_proxy, HTTP_PROXY, or http_proxy is set
  const proxy = process.env['HTTPS_PROXY'] || process.env['https_proxy'] ||
      process.env['HTTP_PROXY'] || process.env['http_proxy'] || '';

  // Using object destructuring to construct the options object for the
  // http request.  the '...url.parse(targetUri)' part fills in the host,
  // path, protocol, etc from the targetUri and then we set the agent to the
  // default agent which is overridden a few lines down if there is a proxy
  const options = {...url.parse(uri), agent: https.globalAgent};

  if (proxy !== '') {
    options.agent = new HttpsProxyAgent(proxy);
  }

  const request = https.get(uri, response => {
    const bar = new ProgressBar('[:bar] :rate/bps :percent :etas', {
      complete: '=',
      incomplete: ' ',
      width: 30,
      total: parseInt(response.headers['content-length'], 10)
    });

    if (uri.endsWith('.zip')) {
      // Save zip file to disk, extract, and delete the downloaded zip file.
      const tempFileName = path.join(__dirname, '_tmp.zip');
      const outputFile = fs.createWriteStream(tempFileName);

      response.on('data', chunk => bar.tick(chunk.length))
          .pipe(outputFile)
          .on('close', async () => {
            const zipFile = new zip(tempFileName);
            zipFile.extractAllTo(destPath, true /* overwrite */);

            await unlink(tempFileName);

            if (callback !== undefined) {
              callback();
            }
          });
    } else if (uri.endsWith('.tar.gz')) {
      response.on('data', chunk => bar.tick(chunk.length))
          .pipe(tar.x({C: destPath, strict: true}))
          .on('close', () => {
            if (callback !== undefined) {
              callback();
            }
          });
    } else {
      throw new Error(`Unsupported packed resource: ${uri}`);
    }
  });
  request.end();
}
async function downloadAndUnpackResource(uri, destPath, callback) {
  // If HTTPS_PROXY, https_proxy, HTTP_PROXY, or http_proxy is set
  const proxy = process.env['HTTPS_PROXY'] || process.env['https_proxy'] ||
      process.env['HTTP_PROXY'] || process.env['http_proxy'] || '';

  // Using object destructuring to construct the options object for the
  // http request.  the '...url.parse(targetUri)' part fills in the host,
  // path, protocol, etc from the targetUri and then we set the agent to the
  // default agent which is overridden a few lines down if there is a proxy
  const options = {...url.parse(uri), agent: https.globalAgent};

  if (proxy !== '') {
    options.agent = new HttpsProxyAgent(proxy);
  }

  const request = https.get(uri, response => {
    const bar = new ProgressBar('[:bar] :rate/bps :percent :etas', {
      complete: '=',
      incomplete: ' ',
      width: 30,
      total: parseInt(response.headers['content-length'], 10)
    });

    if (uri.endsWith('.zip')) {
      // Save zip file to disk, extract, and delete the downloaded zip file.
      const tempFileName = path.join(__dirname, '_tmp.zip');
      const outputFile = fs.createWriteStream(tempFileName);

      response.on('data', chunk => bar.tick(chunk.length))
          .pipe(outputFile)
          .on('close', async () => {
            const zipFile = new zip(tempFileName);
            zipFile.extractAllTo(destPath, true /* overwrite */);

            await unlink(tempFileName);

            if (callback !== undefined) {
              callback();
            }
          });
    } else if (uri.endsWith('.tar.gz')) {
      response.on('data', chunk => bar.tick(chunk.length))
          .pipe(tar.x({C: destPath, strict: true}))
          .on('close', () => {
            if (callback !== undefined) {
              callback();
            }
          });
    } else {
      throw new Error(`Unsupported packed resource: ${uri}`);
    }
  });
  request.end();
}
Downloads and unpacks a given tarball or zip file at a given path.
@param {string} uri The path of the compressed file to download and extract.
@param {string} destPath The destination path for the compressed content.
@param {Function} callback Handler for when downloading and extraction is
complete.