base64
Base64 encoding/decoding library.
Classes & types
type
base64.Alphabet
The base64 encoding/decoding alphabet, created by base64.alphabet.
type
base64.Options
Base64 encoding/decoding options.
type
base64.Variant
Base64 encoding/decoding options variant.
Functions
base64.alphabet | Creates a base64 alphabet with encoding and decoding maps. |
base64.decode | Decodes the specified base64 encoded string. |
base64.encode | Encodes the specified string to base64. |
base64.validate | Checks if the specified base64 encoded string is valid, follows the same rules as base64.decode. |
#base64.alphabet
function base64.alphabet(alphabet_str: string): base64.Alphabet
Creates a base64 alphabet with encoding and decoding maps.
Parameters
| Name | Type | Description |
|---|---|---|
alphabet_str | string | The alphabet string, 64 unique non-whitespace characters. |
Returns
| Type | Name | Description |
|---|---|---|
base64.Alphabet | alphabet | The alphabet. |
#base64.decode
function base64.decode(base64_str: string, options?: base64.Options): string
Decodes the specified base64 encoded string.
Whitespace ( including line breaks ) is ignored, padding is optional but must be correct if present.
Throws an error if the string has invalid length, padding or characters.
Parameters
| Name | Type | Description |
|---|---|---|
base64_str | string | The base64 encoded string to decode. |
optionsoptional | base64.Options | The base64 encoding options, default is the standard variant. |
Returns
| Type | Name | Description |
|---|---|---|
string | raw_str | The decoded string. |
#base64.encode
function base64.encode(raw_str: string, options?: base64.Options): string
Encodes the specified string to base64.
Parameters
| Name | Type | Description |
|---|---|---|
raw_str | string | The string to encode. |
optionsoptional | base64.Options | The base64 encoding options, default is the standard variant. |
Returns
| Type | Name | Description |
|---|---|---|
string | base64_str | The encoded string. |
#base64.validate
function base64.validate(base64_str: string, options?: base64.Options): boolean, nil | string
Checks if the specified base64 encoded string is valid, follows the same rules as base64.decode.
Parameters
| Name | Type | Description |
|---|---|---|
base64_str | string | The base64 encoded string to check. |
optionsoptional | base64.Options | The base64 encoding options, default is the standard variant. |
Returns
| Type | Name | Description |
|---|---|---|
boolean | is_valid | true if the base64 string is valid, false otherwise |
nil | string | err_msg | The error message. |