nupp.codec.base64
Standard base64.
const base64 = require("nupp.codec.base64")
const text = base64.encode("Nupp")
print(text) -- TnVwcA==
print(assert(base64.decode(text))) -- NuppBoth entries are @aot, and both work a word at a time rather than a byte at a time: twelve input bytes are three aligned words and four twenty-four bit groups, and four output bytes are one word. The alphabet and its inverse are const strings, so a compiled entry reads them out of static arrays whose bounds the code generator holds rather than out of a rooted argument whose length it has to load. With aot = "off" this is the same source running on LuaJIT.
bench/base64 measures what that is worth, and measures it against the vectorized C it could have been.
Module contents
Functions
| Function | Kind | Description |
|---|---|---|
decode | function | Decodes canonical standard base64 with required padding. |
encode | function | Encodes bytes as standard base64, padded. |
Functions#
base64.decodefunction#
Decodes canonical standard base64 with required padding.
Text that is not canonical padded base64 is an ordinary answer, as it is for nupp.codec.hex.decode: nil and the reason.
assert(nupp.codec.base64.decode("TnVwcA==") == "Nupp")
local bytes, reason = nupp.codec.base64.decode("TnVwcA")
assert(bytes == nil and reason ~= nil)Arguments
| Name | Type | Description |
|---|---|---|
text | string | the text to decode |
Returns
| Type | Description |
|---|---|
string? | the decoded bytes, or nil when the text is not base64 |
string? | why the text is not base64, when it is not |
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 |