@sentry/react-native
Version:
Official Sentry SDK for react-native
23 lines • 1.01 kB
JavaScript
import { base64StringFromByteArray } from '../vendor';
// Chunk size for `String.fromCharCode.apply` — keeps argument count well below
// engine limits while still amortising the call overhead across many bytes.
const CHUNK_SIZE = 0x8000;
/**
* Encodes a byte array to base64. Uses the runtime's native `btoa` when
* available — Hermes exposes it natively, and some JSC builds do too — which
* is significantly faster than the pure-JS encoder for the envelope payloads
* going through `RNSentry.captureEnvelope`. Falls back to the bundled JS
* encoder when `btoa` is missing.
*/
export function encodeToBase64(bytes) {
const nativeBtoa = globalThis.btoa;
if (typeof nativeBtoa !== 'function') {
return base64StringFromByteArray(bytes);
}
let binary = '';
for (let i = 0; i < bytes.length; i += CHUNK_SIZE) {
binary += String.fromCharCode.apply(null, bytes.subarray(i, i + CHUNK_SIZE));
}
return nativeBtoa(binary);
}
//# sourceMappingURL=base64.js.map