Open
Description
Yeah, the return type is a problem even without the streaming option too. TypeScript thinks it’s a normal shaped response object, but instead it returns an ArrayBuffer
iirc.
Originally posted by @amacneil in octokit/rest.js#12 (comment)
Here is the magic required to stream release assets to a file using rest.js, typescript, and async/await:
import { Octokit } from "@octokit/rest";
import { createWriteStream } from "node:fs";
import { join } from "node:path";
import { pipeline } from "node:stream/promises";
async function fetchAsset() {
const octokit = new Octokit({ auth: process.env.GITHUB_TOKEN });
const asset = await octokit.rest.repos.getReleaseAsset({
owner: "foxglove",
repo: "app",
asset_id: 12345,
headers: {
accept: "application/octet-stream",
},
request: {
parseSuccessResponseBody: false, // required to access response as stream
},
});
const assetStream = asset.data as unknown as NodeJS.ReadableStream;
const outputFile = createWriteStream(join("outputdir", "file.zip"));
await pipeline(assetStream, outputFile);
}
Originally posted by @amacneil in octokit/rest.js#12 (comment)
Metadata
Metadata
Assignees
Type
Projects
Status
🔥 Backlog