diff --git a/mobile/app/(tabs)/import.tsx b/mobile/app/(tabs)/import.tsx index beb99dc..abf250b 100644 --- a/mobile/app/(tabs)/import.tsx +++ b/mobile/app/(tabs)/import.tsx @@ -228,10 +228,21 @@ async function fetchWheelBase64(instanceUrl: string): Promise { const resp = await fetch(wheelUrl); if (!resp.ok) throw new Error(`Could not download Bincio engine (${resp.status}). Is the instance running?`); const buf = await resp.arrayBuffer(); - _cachedWheelBase64 = Buffer.from(buf).toString('base64'); + _cachedWheelBase64 = arrayBufferToBase64(buf); return _cachedWheelBase64; } +function arrayBufferToBase64(buf: ArrayBuffer): string { + const bytes = new Uint8Array(buf); + let binary = ''; + // Process in chunks to avoid spread-operator stack overflow on large arrays. + const CHUNK = 8192; + for (let i = 0; i < bytes.length; i += CHUNK) { + binary += String.fromCharCode(...(bytes.subarray(i, i + CHUNK) as unknown as number[])); + } + return btoa(binary); +} + // ── Styles ─────────────────────────────────────────────────────────────────── const styles = StyleSheet.create({