Converts a ReadableStream to an array by collecting all chunks.
Reads the entire stream into memory, collecting all chunks into an array. Use with caution on large or infinite streams as it loads everything into memory.
Stream element type
ReadableStream to convert
Promise resolving to array of all stream chunks
const stream = fetchDataStream();const items = await stream2array(stream);console.log(`Received ${items.length} items`);// Process stream as arrayconst numbers = await stream2array(numberStream);const sum = numbers.reduce((a, b) => a + b, 0); Copy
const stream = fetchDataStream();const items = await stream2array(stream);console.log(`Received ${items.length} items`);// Process stream as arrayconst numbers = await stream2array(numberStream);const sum = numbers.reduce((a, b) => a + b, 0);
Converts a ReadableStream to an array by collecting all chunks.
Reads the entire stream into memory, collecting all chunks into an array. Use with caution on large or infinite streams as it loads everything into memory.