MCPcopy Index your code
hub / github.com/TanStack/ai / arrayBufferToBase64

Function arrayBufferToBase64

packages/ai-grok/src/utils/audio.ts:186–202  ·  view source on GitHub ↗
(buffer: ArrayBuffer)

Source from the content-addressed store, hash-verified

184 * call can hit `Maximum call stack size exceeded`.
185 */
186export function arrayBufferToBase64(buffer: ArrayBuffer): string {
187 if (typeof Buffer !== 'undefined') {
188 return Buffer.from(buffer).toString('base64')
189 }
190 const bytes = new Uint8Array(buffer)
191 const chunkSize = 0x8000
192 let binary = ''
193 for (let i = 0; i < bytes.length; i += chunkSize) {
194 const end = Math.min(i + chunkSize, bytes.length)
195 binary += String.fromCharCode.apply(
196 null,
197 // eslint-disable-next-line no-restricted-syntax -- TS lib types String.fromCharCode.apply as Array<number> but runtime accepts any ArrayLike
198 bytes.subarray(i, end) as unknown as Array<number>,
199 )
200 }
201 return btoa(binary)
202}
203
204function base64ToArrayBuffer(base64: string): ArrayBuffer {
205 let binary: string

Callers 1

generateSpeechMethod · 0.90

Calls 2

toStringMethod · 0.80
fromMethod · 0.80

Tested by

no test coverage detected