demo · v143

Streaming vs bytes

When to pick blob.bytes() over blob.stream(): bytes() is best when you need the whole payload in memory anyway. This page benchmarks three paths on a blob of a size you choose, plus a peak-memory note.

blob.bytes()

ms
one allocation, no copy round-trip

arrayBuffer() → Uint8Array

ms
two-step, extra view construct

stream() concat

ms
chunked reads, peak ~2× memory
Click Benchmark.

which one to pick

// You need the whole thing in memory? → bytes()
const u8 = await blob.bytes();

// You can process chunks as they arrive? → stream()
for await (const chunk of blob.stream()) {
  hash.update(chunk);
}

// You need an ArrayBuffer specifically? → arrayBuffer()
const view = new DataView(await blob.arrayBuffer());

why this angle

The other concept compares bytes() against the arrayBuffer round-trip. This one adds the third option — stream() — and helps you pick the right tool. Streaming was already the answer for "process as you go"; bytes() is now the answer for "I need it all".

see also