3.5. Base64 encoding and decoding
The BASE64 module implements Base64 encoding and decoding.
It provides base64_encode and base64_decode for converting between binary data
(strings or array<uint8>) and Base64 text representation.
All functions and symbols are in “base64” module, use require to get access to it.
require daslib/base64
Example:
require daslib/base64
[export]
def main() {
let encoded = base64_encode("Hello, daslang!")
print("encoded: {encoded}\n")
let decoded = base64_decode(encoded)
print("decoded: {decoded.text}\n")
}
// output:
// encoded: SGVsbG8sIGRhU2NyaXB0IQ==
// decoded: Hello, daslang!
3.5.1. Encoding
- base64.BASE64_ENCODE_OUT_SIZE(s: int): int
Returns the encoded output size for binary data of length s.
- Arguments:
s : int
3.5.1.1. base64_encode
- base64.base64_encode(_inp: string): string
Encodes a string to its Base64 text representation.
- Arguments:
_inp : string
- base64.base64_encode(inp: array<uint8>|array<uint8>#): auto
3.5.2. Decoding
- base64.BASE64_DECODE_OUT_SIZE(s: int): int
Returns the maximum decoded output size for a Base64 string of length s.
- Arguments:
s : int
3.5.2.1. base64_decode
- base64.base64_decode(_in: string): tuple<text:string;size:int>
Decodes a Base64-encoded string. Returns a tuple of the decoded text and its byte length.
- Arguments:
_in : string
- base64.base64_decode(_in: string; out: array<uint8>): int