| 362 | }); |
| 363 | |
| 364 | function streamingResponse(chunks: Uint8Array[], total: number): Response { |
| 365 | const body = new ReadableStream<Uint8Array>({ |
| 366 | start(controller) { |
| 367 | for (const chunk of chunks) controller.enqueue(chunk); |
| 368 | controller.close(); |
| 369 | }, |
| 370 | }); |
| 371 | return new Response(body, { status: 200, headers: { 'content-length': String(total) } }); |
| 372 | } |
| 373 | |
| 374 | it('streams the body and reports cumulative byte progress with the total', async () => { |
| 375 | const chunks = [new Uint8Array([1, 2, 3]), new Uint8Array([4, 5]), new Uint8Array([6, 7, 8, 9])]; |