Streaming

Consume and count raw bytes from this site’s demo stream. This minimal browser snippet does not parse NDJSON.

import { Http, bare } from "fetchzen";
const api = Http.create(`${location.origin}/api/examples/`, {
cache: false, secure: false, preset: bare,
});
const stream = await api.get<ReadableStream<Uint8Array> | null>("stream", {
responseType: "stream",
});
if (!stream) throw new Error("No response stream");
const reader = stream.getReader();
let bytes = 0;
try {
while (true) {
const { value, done } = await reader.read();
if (done) break;
bytes += value.byteLength;
if (bytes > 65_536) throw new Error("Stream limit exceeded");
console.log(bytes);
}
} finally {
try { await reader.cancel(); }
finally { reader.releaseLock(); }
}
Try this requestIncremental NDJSON

Only Run sends a request to this site's demo API. Use synthetic data only; do not send secrets or personal files. Uploads are counted, not stored.

Ready. No request sent.

Result

Choose Run to see the response.
Event log
No events yet.

The panel adds bounded application-level NDJSON parsing for six records, handling split UTF-8, split lines and decoder flush. NDJSON is not a built-in client parser; chunks are not necessarily complete records. Stream support depends on the runtime. Streamed request bodies are separate: the client supplies duplex: "half" when omitted, but some browsers reject them.

Next: download or file transfers.