Skip to main content

API Reference

Classes

Bytes

Immutable sequence of binary data.

Methods

NameDescription
at
Get the byte at the given index.
copy
Create a copy of the bytes value.
slice
Get the slice of the bytes value from the given start index to the given end index.
toBase64
Convert the bytes value to a base64 encoded string.
toHex
Convert the bytes value to a hex encoded string.
toRaw
Convert the bytes value to an array of byte values.
tryAt
Get the byte at the given index, returning nil if the index is out of bounds.

at
at(index: num): num

Get the byte at the given index.

indexRequired
  • Type: num

index of the value to get.


copy
copy(): Bytes

Create a copy of the bytes value.

slice
slice(startIndex: num, endIndex?: num): Bytes

Get the slice of the bytes value from the given start index to the given end index.

startIndexRequired
  • Type: num

index to start the slice.


endIndexOptional
  • Type: num

index to end the slice.


toBase64
toBase64(): str

Convert the bytes value to a base64 encoded string.

toHex
toHex(): str

Convert the bytes value to a hex encoded string.

toRaw
toRaw(): MutArray<num>

Convert the bytes value to an array of byte values.

tryAt
tryAt(index: num): num?

Get the byte at the given index, returning nil if the index is out of bounds.

indexRequired
  • Type: num

index of the value to get.


Static Functions

NameDescription
concat
Concatenate multiple bytes values.
fromBase64
Create a new bytes value from a base64 encoded string.
fromHex
Create a new bytes value from a hex encoded string.
fromRaw
Create a new bytes value from an array of byte values.
fromString
Create a new bytes value from a string.
zeros
Create a new bytes value with the given length, filled with zeros.

concat
Bytes.concat(...values: Array<Bytes>);

Concatenate multiple bytes values.

valuesRequired

the bytes values to concatenate.


fromBase64
Bytes.fromBase64(base64: str);

Create a new bytes value from a base64 encoded string.

base64Required
  • Type: str

The base64 encoded string to create the bytes from.


fromHex
Bytes.fromHex(hex: str);

Create a new bytes value from a hex encoded string.

hexRequired
  • Type: str

The hex encoded string to create the bytes from.


fromRaw
Bytes.fromRaw(values: MutArray<num>);

Create a new bytes value from an array of byte values.

valuesRequired
  • Type: MutArray<num>

The byte values to create the bytes from.


fromString
Bytes.fromString(value: str);

Create a new bytes value from a string.

valueRequired
  • Type: str

The string to create the bytes from.


zeros
Bytes.zeros(length: num);

Create a new bytes value with the given length, filled with zeros.

lengthRequired
  • Type: num

The length of the new bytes value.


Properties

NameTypeDescription
length
numThe length of the bytes.

lengthRequired
length: num;
  • Type: num

The length of the bytes.


Structs

BytesToStringOptions

Options for converting a bytes value to a string.

Initializer

let BytesToStringOptions = BytesToStringOptions{ ... };

Properties

NameTypeDescription
encoding
strThe encoding to use when converting the bytes value to a string.

encodingRequired
encoding: str;
  • Type: str
  • Default: "utf-8"

The encoding to use when converting the bytes value to a string.

https://developer.mozilla.org/en-US/docs/Web/API/Encoding_API/Encodings