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

FunctionKindDescription
decodefunctionDecodes standard base64, padded.
encodefunctionEncodes bytes as standard base64, padded.

Functions#

base64.decodefunction#

function base64.decode(text: string): string

Decodes standard base64, padded.

assert(nupp.codec.base64.decode("TnVwcA==") == "Nupp")

Arguments

NameTypeDescription
textstring

the text to decode

Returns

TypeDescription
string

the decoded bytes

Raises

  • when the length is not a multiple of four, or a character is not in the alphabet

base64.encodefunction#

function base64.encode(value: string): string

Encodes bytes as standard base64, padded.

assert(nupp.codec.base64.encode("Nupp") == "TnVwcA==")

Arguments

NameTypeDescription
valuestring

the bytes to encode

Returns

TypeDescription
string

the encoded text