export function bytesToBase64(bytes: Uint8Array): string { let binary = '' const chunk = 0x8000 for (let i = 0; i < bytes.length; i += chunk) { binary += String.fromCharCode(...bytes.subarray(i, i + chunk)) } return btoa(binary) } export function base64ToBytes(base64: string): Uint8Array { const clean = base64.replace(/^data:[^,]*,/, '').replace(/\s+/g, '') const binary = atob(clean) const bytes = new Uint8Array(binary.length) for (let i = 0; i < binary.length; i += 1) bytes[i] = binary.charCodeAt(i) return bytes }