(stream: ReadableStream<Uint8Array>)
| 100 | } |
| 101 | |
| 102 | async function readStreamToBuffer(stream: ReadableStream<Uint8Array>): Promise<Buffer> { |
| 103 | const reader = stream.getReader(); |
| 104 | const chunks: Buffer[] = []; |
| 105 | |
| 106 | try { |
| 107 | while (true) { |
| 108 | const { done, value } = await reader.read(); |
| 109 | if (done) break; |
| 110 | chunks.push(Buffer.from(value)); |
| 111 | } |
| 112 | } finally { |
| 113 | reader.releaseLock(); |
| 114 | } |
| 115 | |
| 116 | return Buffer.concat(chunks); |
| 117 | } |
| 118 | |
| 119 | function formatBytesAsMegabytes(bytes: number): string { |
| 120 | return `${(bytes / (1024 * 1024)).toFixed(2)}MB`; |
no test coverage detected