(bytes: ArrayBuffer)
| 140 | * Bun) or walk the byte array in a single loop (browser). |
| 141 | */ |
| 142 | export function arrayBufferToBase64(bytes: ArrayBuffer): string { |
| 143 | if (typeof Buffer !== 'undefined' && typeof Buffer.from === 'function') { |
| 144 | return Buffer.from(bytes).toString('base64') |
| 145 | } |
| 146 | const view = new Uint8Array(bytes) |
| 147 | let binary = '' |
| 148 | for (const byte of view) { |
| 149 | binary += String.fromCharCode(byte) |
| 150 | } |
| 151 | return btoa(binary) |
| 152 | } |
no test coverage detected