/** * @fileoverview base64 helper utilities. * @license * SPDX-License-Identifier: Apache-2.0 */ /** Encodes Uint8Array to base64 string. */ export function encode(bytes: Uint8Array): string { let binary = ''; const len = bytes.byteLength; for (let i = 0; i < len; i++) { binary += String.fromCharCode(bytes[i]); } return btoa(binary); } /** Decodes base64 string to Uint8Array. */ export function decode(base64: string): Uint8Array { const binaryString = atob(base64); const len = binaryString.length; const bytes = new Uint8Array(len); for (let i = 0; i < len; i++) { bytes[i] = binaryString.charCodeAt(i); } return bytes; }