Skip to content

Instantly share code, notes, and snippets.

@dartess
Created January 3, 2026 18:59
Show Gist options
  • Select an option

  • Save dartess/8e4410711b548716eb7cc46c835ed7ab to your computer and use it in GitHub Desktop.

Select an option

Save dartess/8e4410711b548716eb7cc46c835ed7ab to your computer and use it in GitHub Desktop.
fetch with progress
// (c) @rdvornov
const response = await fetch('... url goes here ...');
const progressProxyResponse = new Response(new ReadableStream({
async start(controller) {
const totalSize = Number(response.headers.get('content-length'));
const reader = response.body.getReader();
let loadedSize = 0;
while (true) {
const { done, chunk } = await reader.read();
if (done) {
controller.close();
break;
}
controller.enqueue(chunk);
loadedSize += chunk.length;
console.log(`Received ${loadedSize} of ${totalSize}`);
}
}
}));
const data = await progressProxyResponse.json();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment