MCPcopy Create free account
hub / github.com/TanStack/ai / bytesToBase64

Function bytesToBase64

examples/ts-react-chat/src/routes/generation-hooks.tsx:770–788  ·  view source on GitHub ↗
(bytes: Uint8Array)

Source from the content-addressed store, hash-verified

768}
769
770function bytesToBase64(bytes: Uint8Array): string {
771 const alphabet =
772 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
773 let output = ''
774
775 for (let index = 0; index < bytes.length; index += 3) {
776 const first = bytes[index] ?? 0
777 const second = index + 1 < bytes.length ? bytes[index + 1] : undefined
778 const third = index + 2 < bytes.length ? bytes[index + 2] : undefined
779 const combined = (first << 16) | ((second ?? 0) << 8) | (third ?? 0)
780
781 output += alphabet[(combined >> 18) & 63]
782 output += alphabet[(combined >> 12) & 63]
783 output += second === undefined ? '=' : alphabet[(combined >> 6) & 63]
784 output += third === undefined ? '=' : alphabet[combined & 63]
785 }
786
787 return output
788}
789
790function svgDataUrl(title: string, prompt: string, color: string): string {
791 const safeTitle = escapeXml(title)

Callers 1

createToneWavBase64Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected