Files
herolib/aiprompts/v_core/encoding/base64.md
2025-09-02 07:28:13 +02:00

3.5 KiB

module base64

Contents

decode

fn decode(data string) []u8

decode decodes the base64 encoded string value passed in data. Please note: If you need to decode many strings repeatedly, take a look at decode_in_buffer.

Example


assert base64.decode('ViBpbiBiYXNlIDY0') == 'V in base 64'.bytes()

[Return to contents]

decode_in_buffer

fn decode_in_buffer(data &string, buffer &u8) int

decode_in_buffer decodes the base64 encoded string reference passed in data into buffer. decode_in_buffer returns the size of the decoded data in the buffer. Please note: The buffer should be large enough (i.e. 3/4 of the data.len, or larger) to hold the decoded data. Please note: This function does NOT allocate new memory, and is thus suitable for handling very large strings.

[Return to contents]

decode_in_buffer_bytes

fn decode_in_buffer_bytes(data []u8, buffer &u8) int

decode_from_buffer decodes the base64 encoded ASCII bytes from data into buffer. decode_from_buffer returns the size of the decoded data in the buffer. Please note: The buffer should be large enough (i.e. 3/4 of the data.len, or larger) to hold the decoded data. Please note: This function does NOT allocate new memory, and is thus suitable for handling very large strings.

[Return to contents]

decode_str

fn decode_str(data string) string

decode_str is the string variant of decode

[Return to contents]

encode

fn encode(data []u8) string

encode encodes the []u8 value passed in data to base64. Please note: base64 encoding returns a string that is ~ 4/3 larger than the input. Please note: If you need to encode many strings repeatedly, take a look at encode_in_buffer.

Example


assert base64.encode('V in base 64'.bytes()) == 'ViBpbiBiYXNlIDY0'

[Return to contents]

encode_in_buffer

fn encode_in_buffer(data []u8, buffer &u8) int

encode_in_buffer base64 encodes the []u8 passed in data into buffer. encode_in_buffer returns the size of the encoded data in the buffer. Please note: The buffer should be large enough (i.e. 4/3 of the data.len, or larger) to hold the encoded data. Please note: The function does NOT allocate new memory, and is suitable for handling very large strings.

[Return to contents]

encode_str

fn encode_str(data string) string

encode_str is the string variant of encode

[Return to contents]

url_decode

fn url_decode(data string) []u8

url_decode returns a decoded URL string version of the a base64 url encoded string passed in data.

[Return to contents]

url_decode_str

fn url_decode_str(data string) string

url_decode_str is the string variant of url_decode

[Return to contents]

url_encode

fn url_encode(data []u8) string

url_encode returns a base64 URL encoded string version of the value passed in data.

[Return to contents]

url_encode_str

fn url_encode_str(data string) string

url_encode_str is the string variant of url_encode

[Return to contents]

Powered by vdoc. Generated on: 2 Sep 2025 07:18:04