function downloadFile(url, destinationPath, progressCallback) {
  let fulfill;
  let reject;
  let downloadedBytes = 0;
  let totalBytes = 0;

  const promise = new Promise((x, y) => {
    fulfill = x;
    reject = y;
  });

  const request = httpRequest(url, "GET", (response) => {
    if (response.statusCode !== 200) {
      const error = new Error(
        `Download failed: server returned code ${response.statusCode}. URL: ${url}`,
      );
      // consume response data to free up memory
      response.resume();
      reject(error);
      return;
    }
    const file = fs.createWriteStream(destinationPath);
    file.on("finish", () => fulfill());
    file.on("error", (error) => reject(error));
    response.pipe(file);
    totalBytes = Number.parseInt(
      /** @type {string} */ (response.headers["content-length"]),
      10,
    );
    if (progressCallback) {
      response.on("data", onData);
    }
  });
  request.on("error", (error) => reject(error));
  return promise;

  function onData(chunk) {
    downloadedBytes += chunk.length;
    progressCallback(downloadedBytes, totalBytes);
  }
}
@param {string} url
@param {string} destinationPath
@param {?function(number, number)} progressCallback
@return {!Promise}