Uint8Array object represents an array of 8-bit unsigned integers. React Native for Vega includes the standard JavaScript Uint8Array implementation along with additional utility methods for working with binary data.
Available Methods
React Native for Vega’sUint8Array implementation includes the following methods for working with binary data:
Static Methods
Uint8Array.fromBase64(string): Creates a newUint8Arrayfrom a base64-encoded stringUint8Array.fromHex(string): Creates a newUint8Arrayfrom a hexadecimal string
Instance Methods
Uint8Array.prototype.toBase64(): Converts theUint8Arrayto a base64-encoded stringUint8Array.prototype.toHex(): Converts theUint8Arrayto a hexadecimal stringUint8Array.prototype.setFromBase64(string): Populates theUint8Arraywith data from a base64-encoded stringUint8Array.prototype.setFromHex(string): Populates theUint8Arraywith data from a hexadecimal string
Static Methods
Uint8Array.fromBase64(string)
Uint8Array from a base64-encoded string.
Parameters:
- base64String: A string containing base64-encoded data.
Returns:
A newUint8Array containing the decoded data.
Notes:
- Only the default implementation is supported - there is no support for options such as base64url alphabet or lastChunkHandling. The standard base64 alphabet and loose lastChunkHandling are currently the only supported modes of operation.
Example:
Uint8Array.fromHex(string)
Uint8Array from a hexadecimal string.
Parameters:
- hexString: A string containing hexadecimal data. Must have an even length and contain only valid hexadecimal characters (0-9, A-F, a-f).
Returns:
A newUint8Array containing the decoded data.
Example:
Instance Methods
Uint8Array.prototype.toBase64()
Uint8Array to a base64-encoded string.
Returns:
A base64-encoded string representing the binary data.Notes:
- Only the default implementation is supported - there is no support for options such as base64url alphabet or omitPadding. The standard base64 alphabet is used and padding is always included (equivalent to omitPadding: false).
Example:
Uint8Array.prototype.toHex()
Uint8Array to a hexadecimal string.
Returns:
A hexadecimal string representing the binary data.Example:
Uint8Array.prototype.setFromBase64(string)
Uint8Array with data from a base64-encoded string.
Parameters:
- base64String: A string containing base64-encoded data.
Returns:
An object with:- read: Number of characters read from the input string
- written: Number of bytes written to the
Uint8Array
Notes:
- Only the default implementation is supported - there is no support for options such as base64url alphabet or lastChunkHandling. The standard base64 alphabet and loose lastChunkHandling are currently the only supported modes of operation.
Example:
Uint8Array.prototype.setFromHex(string)
Uint8Array with data from a hexadecimal string.
Parameters:
- hexString: A string containing hexadecimal data. Must have an even length and contain only valid hexadecimal characters (0-9, A-F, a-f).
Returns:
An object with:- read: Number of characters read from the input string
- written: Number of bytes written to the
Uint8Array
Example:
Notes
- These methods are optimized for performance and use native implementations where available.
- When working with large binary data, these methods are significantly more efficient than manual conversion approaches.
- These methods are compatible with the standard JavaScript
Uint8ArrayAPI and don’t interfere with existing functionality.

