octokit / rest.js

GitHub REST API client for JavaScript

Home Page:https://octokit.github.io/rest.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How exactly is one meant to save a release asset?

Noxillio opened this issue · comments

I'm able to get assets without a problem, and I am able to get an ArrayBuffer of an asset using the accepts: 'application/octet-stream' header, but no matter what I do I can't get it to save as a file. I am using TypeScript which further complicates the issue as the typing for the data property is either an object with static data, or simply null. It does not include the possibility of being an ArrayBuffer and so I can't work with it. I need advice please.

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

You can override the type of the data property if needed.

As for how to save the file,

import { writeFile } from "node:fs/promises";

await writeFile("filename.ext", Buffer.from(data))

writeFile expects a callback and after putting one in I get an error:

src/index.ts:46:68 - error TS2769: No overload matches this call.
  The last overload gave the following error.
    Argument of type 'OctokitResponse<{ url: string; browser_download_url: string; id: number; node_id: string; name: string; label: string | null; state: "uploaded" | "open"; content_type: string; size: number; download_count: number; created_at: string; updated_at: string; uploader: { ...; } | null; }, 200>' is not assignable to parameter of type 'WithImplicitCoercion<string> | { [Symbol.toPrimitive](hint: "string"): string; }'.

The same thing happens with writeFileSync.

The problem is that the result doesn't include ArrayBuffer as a type. Nothing I do will overcome that issue, even if I use as ArrayBuffer (because that's what the result will be every time in my context).

Use as unknown as ArrayBuffer to forcefully override it

Closing as completed here, thanks @wolfy1339. Please feel free to reopen if there are further issues.