Skip to content

encoding.base64 #

fn 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'

fn 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.

fn 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.

fn decode_str #

fn decode_str(data string) string

decode_str is the string variant of decode

fn 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') == 'ViBpbiBiYXNlIDY0'

fn 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.

fn encode_str #

fn encode_str(data string) string

encode_str is the string variant of encode

fn 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.

fn url_decode_str #

fn url_decode_str(data string) string

url_decode_str is the string variant of url_decode

fn url_encode #

fn url_encode(data []u8) string

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

fn url_encode_str #

fn url_encode_str(data string) string

url_encode_str is the string variant of url_encode