An async loop consumes a web stream chunk by chunk. Stream chunks need not align with logical messages or character boundaries.
Worked example
const source = () =>
new ReadableStream({
start(c) {
c.enqueue("a");
c.enqueue("b");
c.close();
},
});
console.log(await Array.fromAsync(source()));Result
[ 'a', 'b' ]Implementation notes
A text decoder needs to handle characters split across byte chunks. Decode as a stream if the source contains arbitrary UTF-8 text.
Try it yourself
Split one logical record across two chunks and reassemble it.
Open the Node.js example →Editorial date April 25, 2026 · Published December 6, 2026