fix: replace Buffer.from().toString('base64') with btoa helper — Buffer not available in Expo RN
This commit is contained in:
@@ -228,10 +228,21 @@ async function fetchWheelBase64(instanceUrl: string): Promise<string> {
|
|||||||
const resp = await fetch(wheelUrl);
|
const resp = await fetch(wheelUrl);
|
||||||
if (!resp.ok) throw new Error(`Could not download Bincio engine (${resp.status}). Is the instance running?`);
|
if (!resp.ok) throw new Error(`Could not download Bincio engine (${resp.status}). Is the instance running?`);
|
||||||
const buf = await resp.arrayBuffer();
|
const buf = await resp.arrayBuffer();
|
||||||
_cachedWheelBase64 = Buffer.from(buf).toString('base64');
|
_cachedWheelBase64 = arrayBufferToBase64(buf);
|
||||||
return _cachedWheelBase64;
|
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 ───────────────────────────────────────────────────────────────────
|
// ── Styles ───────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
|
|||||||
Reference in New Issue
Block a user