I believe XMLHttpRequest is needed for upload progress events.
Download progress can be measured with fetch already:
async function main() {
let largeFileUrl = "http://download.inspire.net.nz/data/20MB.zip";
let response = await fetch(largeFileUrl);
let contentLength = parseInt(response.headers.get("Content-Length"));
let readTotal = 0;
let buffer = new Uint8Array(4096);
let encoder = new TextEncoder();
while (true) {
let { nread, eof } = await response.body.read(buffer);
readTotal += nread;
let percent = ((readTotal / contentLength) * 100).toFixed(2);
Deno.stdout.write(encoder.encode(`\r${percent}%`));
if (eof) break;
}
}
main();
I really think XMLHttpRequest is a big ole can of worms. It is a really old API with a load of crap to try to make it compatible with the browsers. IMO we really have to draw the line of "browser compatibility" somewhere.
The best thing is that is someone desired, to use the built in Deno bindings to create a polyfill in std and bring it into core if it actually worked well.
I agree with @kitsonk - it would be great if we didn't support XHR.
@MarkTiedemann I believe that "progress events" are available through fetch streaming?
Won鈥檛 implement
Most helpful comment
I really think
XMLHttpRequestis a big ole can of worms. It is a really old API with a load of crap to try to make it compatible with the browsers. IMO we really have to draw the line of "browser compatibility" somewhere.The best thing is that is someone desired, to use the built in Deno bindings to create a polyfill in
stdand bring it into core if it actually worked well.