Skip to content

chanphiromsok/react-native-nitro-base64

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

40 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

react-native-nitro-base64 ⚑

The fastest Base64 library for React Native β€” powered by simdutf SIMD C++ and Nitro Modules.

Processes a 1.3MB image 26x faster than atob/btoa and 1.8x faster than react-native-quick-base64.

iPhone Android
iPhone Android

πŸ€” Why this library?

Most React Native base64 libraries hit the same bottlenecks:

  • 🐒 Pure JS (base64-js) β€” slow. No native acceleration.
  • ⚠️ atob/btoa β€” fast for tiny strings, falls apart on binary data at scale.
  • ⚠️ String-based native β€” crosses the JSI bridge as UTF-16, doubling memory for binary payloads.

react-native-nitro-base64 uses SIMD instructions (AVX-512 on x86, NEON on Apple Silicon) to process 64 bytes per CPU instruction, and exposes ArrayBuffer/Uint8Array APIs that bypass string marshaling entirely.

πŸ“Š Benchmark β€” 30 iterations, iPhone (Apple Silicon)

Tested against react-native-quick-base64@3.0.0

Small image (7KB)

Library Time vs. nitro-base64
⚑ nitro-base64 decodeBuffer / fromByteArray 0.06ms β€”
react-native-quick-base64 0.11ms 1.8x slower
atob / btoa (Hermes) 1.04ms 17x slower

Large image (1.3MB)

Library Time vs. nitro-base64
⚑ nitro-base64 decodeBuffer / fromByteArray 7.5ms β€”
react-native-quick-base64 13.6ms 1.8x slower
atob / btoa (Hermes) 203ms 26x slower

πŸ“¦ Installation

yarn add react-native-nitro-base64
yarn add react-native-nitro-modules

Then follow Nitro's setup guide for autolinking.

πŸ”§ Setup

Call install() once before your app mounts:

// index.js
import { install } from 'react-native-nitro-base64';
import { AppRegistry } from 'react-native';
import App from './src/App';
import { name as appName } from './app.json';

install();
AppRegistry.registerComponent(appName, () => App);

πŸ“– API

Function Input β†’ Output Notes
encode(str, urlSafe?) string β†’ base64 string URL-safe optional
decode(base64) base64 string β†’ string Auto-detects standard & URL-safe
encodeBuffer(ArrayBuffer, urlSafe?) ArrayBuffer β†’ base64 string πŸš€ Zero-copy, fastest for images
decodeBuffer(base64) base64 string β†’ ArrayBuffer πŸš€ Zero-copy, fastest for images
fromByteArray(Uint8Array, urlSafe?) Uint8Array β†’ base64 string Drop-in for react-native-quick-base64
toByteArray(base64) base64 string β†’ Uint8Array Drop-in for react-native-quick-base64

πŸš€ Usage

πŸ–ΌοΈ Images & files β€” encodeBuffer / decodeBuffer

Images are binary data. Sending binary through a JS string crosses the JSI bridge as UTF-16, doubling memory. ArrayBuffer skips that entirely β€” raw bytes go straight to C++.

import { encodeBuffer, decodeBuffer } from 'react-native-nitro-base64';

// Upload image to API
const response = await fetch(imageUri);
const buffer = await response.arrayBuffer();
const base64 = encodeBuffer(buffer); // β†’ "iVBORw0KGgo..."

// Decode API response for <Image> component
const buffer = decodeBuffer(base64String); // β†’ ArrayBuffer

πŸ”‘ Text & JWT β€” encode / decode

import { encode, decode } from 'react-native-nitro-base64';

const encoded = encode('Hello World!');  // "SGVsbG8gV29ybGQh"
const decoded = decode(encoded);         // "Hello World!"

// URL-safe for JWT / URL params
const token = encode(payload, true);

πŸ” Web Crypto & hashing β€” fromByteArray / toByteArray

Drop-in replacement for react-native-quick-base64. Same API, faster engine.

import { fromByteArray, toByteArray } from 'react-native-nitro-base64';

// SHA-256 hash β†’ base64
const hash = new Uint8Array(await crypto.subtle.digest('SHA-256', data));
const encoded = fromByteArray(hash);

// base64 β†’ text
const bytes = toByteArray(base64String);
const text = new TextDecoder().decode(bytes);

πŸ“± Platform Support

Platform Engine
iOS C++ (simdutf, NEON SIMD)
Android C++ (simdutf, NEON / AVX2 SIMD)

πŸ“„ License

MIT

πŸ™ Credits

About

A high-performance, cross-platform Base64 encoding/decoding module for React Native, powered by C++ and simdutf. Implements WHATWG forgiving-base64 and supports both standard and URL-safe variants.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors