Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | /** |
| 2 | * Convert ArrayBuffer to base64. |
| 3 | */ |
| 4 | export function arrayBufferToBase64(buffer: ArrayBuffer) { |
| 5 | const bytes = new Uint8Array(buffer); |
| 6 | let binary = ''; |
| 7 | for (let i = 0; i < bytes.length; i++) { |
| 8 | binary += String.fromCharCode(bytes[i]); |
| 9 | } |
| 10 | return btoa(binary); |
| 11 | } |
| 12 | |
| 13 | // Helper function to convert base64 string to Uint8Array (cross-platform) |
| 14 | export const base64ToUint8Array = (base64: string): Uint8Array => { |
| 15 | const binary = atob(base64); |
| 16 | const bytes = new Uint8Array(binary.length); |
| 17 | for (let i = 0; i < binary.length; i++) { |
| 18 | bytes[i] = binary.charCodeAt(i); |
| 19 | } |
| 20 | return bytes; |
| 21 | }; |
| 22 | |
| 23 | // Helper function to convert Uint8Array to base64 string (cross-platform) |
| 24 | export const uint8ArrayToBase64 = (bytes: Uint8Array): string => { |
| 25 | let binary = ''; |
| 26 | for (let i = 0; i < bytes.length; i++) { |
| 27 | binary += String.fromCharCode(bytes[i]); |
| 28 | } |
| 29 | return btoa(binary); |
| 30 | }; |