private async downloadAddon()

in src/controller/addonController.ts [245:278]


  private async downloadAddon(fileID: string, filepath: string) {
    const dest = fs.createWriteStream(filepath, { flags: "w" });
    const handleError = async () => {
      const errorMessages: ErrorMessages = {
        window: {
          other: `Could not download addon to ${filepath}`,
        },
        thrown: {
          other: "Download failed",
        },
      };
      await NotificationView.showErrorMessage(
        errorMessages,
        "other",
        this.downloadAddon,
        [fileID, filepath]
      );
      dest.close();
    };

    dest.on("error", handleError);
    NotificationView.promptProgress("Downloading Addon", async () => {
      try {
        const response = await this.fetchDownloadFile(fileID);
        const buffer = await response.buffer();
        dest.write(buffer);
        dest.end();
      } catch (error) {
        handleError();
      }
    });

    return dest;
  }