Base64
ClassUtility class for encoding and decoding data in base64 format.
Index
Methods
Example
// Encode a string to base64
const encoded = Base64.encodeString('Hello, Lens Studio!');
console.log('Encoded:', encoded);
// Decode base64 back to bytes
const decoded = Base64.decode(encoded);
const text = new TextDecoder().decode(decoded);
console.log('Decoded text:', text);
// Round-trip binary data through base64
const original = new Uint8Array([72, 101, 108, 108, 111]);
const b64 = Base64.encode(original);
const restored = Base64.decode(b64);
console.log('Round-trip match:', original.every((v, i) => v === restored[i]));
Methods
decode()
staticdecode(value):Uint8Array
Decode a base64 string to a Uint8Array.
Parameters
| Parameter | Type |
|---|---|
value | string |
Returns
Uint8Array
encode()
staticencode(data):string
Encode a Uint8Array to a base64 string.
Parameters
| Parameter | Type |
|---|---|
data | Uint8Array |
Returns
string
encodeString()
staticencodeString(str):string
Encode a string to a base64 string.
Parameters
| Parameter | Type |
|---|---|
str | string |
Returns
string