The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | /** |
| 2 | * Base64 for byte arrays, on the native `toBase64`/`fromBase64` when the |
| 3 | * runtime has them and `btoa`/`atob` otherwise. |
| 4 | */ |
| 5 | export const bytesToBase64 = (bytes: Uint8Array): string => { |
| 6 | const encode = (bytes as Uint8Array & { toBase64?: () => string }).toBase64; |
| 7 | if (typeof encode === "function") return encode.call(bytes); |
| 8 | let binary = ""; |
| 9 | for (const byte of bytes) binary += String.fromCharCode(byte); |
| 10 | return btoa(binary); |
| 11 | }; |
| 12 | |
| 13 | export const base64ToBytes = (b64: string): Uint8Array => { |
| 14 | const decode = ( |
| 15 | Uint8Array as Uint8ArrayConstructor & { fromBase64?: (value: string) => Uint8Array } |
| 16 | ).fromBase64; |
| 17 | if (typeof decode === "function") return decode.call(Uint8Array, b64); |
| 18 | const binary = atob(b64); |
| 19 | const out = new Uint8Array(binary.length); |
| 20 | for (let i = 0; i < binary.length; i++) out[i] = binary.charCodeAt(i); |
| 21 | return out; |
| 22 | }; |