( bytes: Uint8Array, stream: CompressionStream | DecompressionStream )
| 456 | } |
| 457 | |
| 458 | async function transformBytes( |
| 459 | bytes: Uint8Array, |
| 460 | stream: CompressionStream | DecompressionStream |
| 461 | ): Promise<Uint8Array> { |
| 462 | const input = new Blob([new Uint8Array(bytes)]).stream(); |
| 463 | const transformed = input.pipeThrough(stream); |
| 464 | const chunks: Uint8Array[] = []; |
| 465 | const reader = transformed.getReader(); |
| 466 | for (;;) { |
| 467 | const { done, value } = await reader.read(); |
| 468 | if (done) break; |
| 469 | chunks.push(value); |
| 470 | } |
| 471 | return concatBytes(chunks); |
| 472 | } |
| 473 | |
| 474 | function concatBytes(chunks: Uint8Array[]): Uint8Array { |
| 475 | const total = chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0); |
no test coverage detected