You're buffering the response, that's why the memory is growing.
Deno.open
now returns a FsFile
which contains a WritableStream
in .writable
property, so you can just pipe the response to it.
const res = await fetch('https://speed.hetzner.de/10GB.bin');
const file = await Deno.open('./10gb.bin', { create: true, write: true })
await res.body.pipeTo(file.writable);
file.close();
If you want to do something else instead of writing to a file, res.body
is a ReadableStream
, so you could async iterate over it.
for await (const chunk of res.body) {
// do something with each chunk
}
Regarding why it stops at 4GB I'm not sure, but it may have to do with ArrayBuffer
/ UInt8Array
limits, since 4GB is around 2³² bytes, which is the limit of TypedArray
, at least in most runtimes.
Updated my answer for latest Deno version