(buffer: unknown)
| 402 | } |
| 403 | |
| 404 | function toBase64(buffer: unknown): string { |
| 405 | //TODO: replace with when is Baseline widely available |
| 406 | // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array/toBase64 |
| 407 | const bytes = new Uint8Array(buffer as ArrayBufferLike); |
| 408 | |
| 409 | const CHUNK_SIZE = 0x8000; // 32,768 bytes (~32 KB) per chunk, to avoid stack overflow |
| 410 | |
| 411 | let binaryString = ''; |
| 412 | |
| 413 | for (let i = 0; i < bytes.length; i += CHUNK_SIZE) { |
| 414 | const chunk = bytes.subarray(i, i + CHUNK_SIZE); |
| 415 | binaryString += String.fromCharCode.apply(null, chunk as unknown as number[]); |
| 416 | } |
| 417 | return btoa(binaryString); |
| 418 | } |
| 419 | |
| 420 | function fromBase64(base64: string): ArrayBuffer { |
| 421 | const binary = atob(base64); |
no test coverage detected
searching dependent graphs…