Skip to content
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/snaps-utils/src/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import type { VirtualFile } from './virtual-file';
*/
export async function encodeBase64(input: Uint8Array | VirtualFile | string) {
const bytes = getBytes(input);
// In the browser, FileReader is much faster than bytesToBase64.
if ('FileReader' in globalThis) {
const isReactNative =
typeof navigator !== 'undefined' && navigator.product === 'ReactNative';
// In the browser, FileReader is much faster than bytesToBase64. This is not supported in React Native however.
if ('FileReader' in globalThis && !isReactNative) {
return await new Promise((resolve, reject) => {
const reader = Object.assign(new FileReader(), {
onload: () =>
Expand Down
Loading