API Reference
Classes
Bytes
Immutable sequence of binary data.
Methods
Name | Description |
---|---|
| Get the byte at the given index. |
| Create a copy of the bytes value. |
| Get the slice of the bytes value from the given start index to the given end index. |
| Convert the bytes value to a base64 encoded string. |
| Convert the bytes value to a hex encoded string. |
| Convert the bytes value to an array of byte values. |
| 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.
index
Required
- 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.
startIndex
Required
- Type: num
index to start the slice.
endIndex
Optional
- 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.
index
Required
- Type: num
index of the value to get.
Static Functions
Name | Description |
---|---|
| Concatenate multiple bytes values. |
| Create a new bytes value from a base64 encoded string. |
| Create a new bytes value from a hex encoded string. |
| Create a new bytes value from an array of byte values. |
| Create a new bytes value from a string. |
| Create a new bytes value with the given length, filled with zeros. |
concat
Bytes.concat(...values: Array<Bytes>);
Concatenate multiple bytes
values.
values
Required
- Type: Bytes
the bytes
values to concatenate.
fromBase64
Bytes.fromBase64(base64: str);
Create a new bytes
value from a base64 encoded string.
base64
Required
- 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.
hex
Required
- 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.
values
Required
- Type: MutArray<num>
The byte values to create the bytes
from.
fromString
Bytes.fromString(value: str);
Create a new bytes
value from a string.
value
Required
- 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.
length
Required
- Type: num
The length of the new bytes
value.
Properties
Name | Type | Description |
---|---|---|
| num | The length of the bytes. |
length
Required
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
Name | Type | Description |
---|---|---|
| str | The encoding to use when converting the bytes value to a string. |
encoding
Required
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