nupp.codec.base64
Standard base64, encoded and decoded as @aot entries.
The alphabet and its inverse are const strings, so a compiled entry reads them out of static arrays whose bounds the C compiler holds rather than out of a rooted argument whose length it must load. With aot = "off" this is the same source on LuaJIT.
Whole words rather than single bytes on both sides: twelve input bytes are three aligned words and four twenty-four bit groups, and four output bytes are one word. bench/base64 measures what that is worth, and measures this against the vectorized C it could be.
Module contents
Functions
| Function | Kind | Description |
|---|---|---|
decode | function | Decodes standard base64, padded. |
encode | function | Encodes bytes as standard base64, padded. |
Functions#
base64.decodefunction#
function base64.decode(text: string): stringDecodes standard base64, padded.
Arguments
| Name | Type | Description |
|---|---|---|
text | string | the text to decode |
Returns
| Type | Description |
|---|---|
string | the decoded bytes |
Raises
when the length is not a multiple of four, or a character is not in the alphabet
base64.encodefunction#
Encodes bytes as standard base64, padded.
Arguments
| Name | Type | Description |
|---|---|---|
value | string | the bytes to encode |
Returns
| Type | Description |
|---|---|
string | the encoded text |