| 57 | } |
| 58 | |
| 59 | export async function webStreamFromArray(chunks) { |
| 60 | const readable = new ReadableStream({ |
| 61 | start(controller) { |
| 62 | for (const chunk of chunks) controller.enqueue(chunk); |
| 63 | controller.close(); |
| 64 | } |
| 65 | }); |
| 66 | const reader = readable.getReader(); |
| 67 | const result = []; |
| 68 | while (true) { |
| 69 | const { value, done } = await reader.read(); |
| 70 | if (done) break; |
| 71 | result.push(value); |
| 72 | } |
| 73 | return result; |
| 74 | } |
| 75 | |
| 76 | // ============================================================================= |
| 77 | // Transform Benchmarks |