3.5 KiB
module base64
Contents
- decode
- decode_in_buffer
- decode_in_buffer_bytes
- decode_str
- encode
- encode_in_buffer
- encode_str
- url_decode
- url_decode_str
- url_encode
- url_encode_str
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()
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.
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.
decode_str
fn decode_str(data string) string
decode_str is the string variant of decode
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'
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.
encode_str
fn encode_str(data string) string
encode_str is the string variant of encode
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.
url_decode_str
fn url_decode_str(data string) string
url_decode_str is the string variant of url_decode
url_encode
fn url_encode(data []u8) string
url_encode returns a base64 URL encoded string version of the value passed in data.
url_encode_str
fn url_encode_str(data string) string
url_encode_str is the string variant of url_encode