Skip to main content
Version: Current

Bytes Actions

bytes.fromBase64String(base64: string): Uint8Array

Converts the given Base64 string into a byte array that contains the data represented by the string. Returns the new Uint8Array array.

The first parameter is a string and is the Base64 formatted string that should be converted to a Uint8Array byte array.

Examples

Convert a Base64 string into bytes
const data = bytes.fromBase64String('aGVsbG8='); // "hello" encoded in Base64

bytes.fromBase64Url(url: string): Blob

Converts the given Data URL into a blob object.

Returns a blob that contains the binary data. Returns null if the URL is not a valid Data URL.

The first parameter is a string and is the URL.

Examples

Convert a data URL to a blob
const blob = bytes.fromBase64Url('data:image/png;base64,aGVsbG8='); // "hello" encoded in Base64

bytes.fromHexString(hex: string): Uint8Array

Converts the given hexadecimal string into a byte array that contains the data represented by the string. Returns the new Uint8Array array.

The first parameter is a string and is the hexadecimal string that should be converted to a byte array.

Examples

Convert a hex string into bytes
const data = bytes.fromHexString('fffefd'); // 255, 254, 253 in hex

bytes.toBase64String(bytes: Uint8Array): string

Formats the given bytes into a string that contains the Base64 representation of the given data. Returns the Base64 string.

The first parameter is a Uint8Array and is the bytes that should be formatted into Base64.

Examples

Format a byte array into Base64
os.toast(bytes.toBase64String(new Uint8Array([ 255, 254, 253 ])));

bytes.toBase64Url(bytes: (string | Uint8Array), mimeType?: string): string

Converts the given bytes into a string that contains the Base64 Data URL representation of the given data.

The first parameter is a (string | Uint8Array) and is the data that should be converted to a Base64 Data URL. If given a string, then it should be valid Base 64 data.

The second parameter is optional and is a string and is the MIME Type of the data. If omitted, then image/png will be used.

Examples

Convert some bytes to a base 64 image/png data URL
const data = bytes.toBase64Url(new Uint8Array([ 255, 254, 253 ]));
Convert a base 64 string to a text/plain base 64 data URL
const data = bytes.toBase64Url('aGVsbG8=', 'text/plain'); // "hello" encoded in Base64

bytes.toHexString(bytes: Uint8Array): string

Formats the given bytes into a string that contains the hexadecimal representation of the given data. Returns the hex string.

The first parameter is a Uint8Array and is the bytes that should be formatted into hexadecimal.

Examples

Format a byte array into hexadecimal
os.toast(bytes.toHexString(new Uint8Array([ 255, 254, 253 ]))); // fffefd in bytes