Skip to content

Instantly share code, notes, and snippets.

@scubbo
Created November 14, 2024 22:41
Show Gist options
  • Save scubbo/ae91d5a4f939edfa5abae0618c7247e5 to your computer and use it in GitHub Desktop.
Save scubbo/ae91d5a4f939edfa5abae0618c7247e5 to your computer and use it in GitHub Desktop.
ReadableStream<Uint8Array> to String
// For https://stackoverflow.com/questions/49014689/http-post-request-with-typescript
const reader = response.body.getReader();
const stream = new ReadableStream({
start(controller) {
function push() {
reader.read().then(({ done, value }) => {
if (done) {
controller.close();
return;
}
controller.enqueue(value);
push();
});
}
push();
}
});
const responseText = await new Response(stream).text()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment