Created
November 14, 2024 22:41
-
-
Save scubbo/ae91d5a4f939edfa5abae0618c7247e5 to your computer and use it in GitHub Desktop.
ReadableStream<Uint8Array> to String
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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