* Read the entire response body and return the raw Uint8Array for it.
()
| 269 | * Read the entire response body and return the raw Uint8Array for it. |
| 270 | */ |
| 271 | async readAll(): Promise<Uint8Array> { |
| 272 | if (!this.body) { |
| 273 | throw new Error("no response body") |
| 274 | } |
| 275 | |
| 276 | let curBuffer = new Uint8Array(); |
| 277 | let readBuf = new Uint8Array(1024 * 10); |
| 278 | |
| 279 | while (true) { |
| 280 | const n = await this.body.read(readBuf); |
| 281 | const newBuffer = new Uint8Array(curBuffer.length + n); |
| 282 | newBuffer.set(curBuffer, 0); |
| 283 | newBuffer.set(readBuf.slice(0, n), curBuffer.length); |
| 284 | curBuffer = newBuffer; |
| 285 | |
| 286 | if (n === 0) { |
| 287 | break; |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | return curBuffer; |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * Read and decode the response body as json |
no test coverage detected