Skip to content

Latest commit

 

History

History
74 lines (51 loc) · 1.83 KB

File metadata and controls

74 lines (51 loc) · 1.83 KB

base64

Summary

geode.utils.base64 encodes and decodes base64 text. Every function takes an optional variant that picks the alphabet and padding. Use the Variant table for the values.

Name Value Notes
Normal 0 standard alphabet
NormalNoPad 1 standard alphabet, no padding
Url 2 url safe alphabet
UrlWithPad 3 url safe alphabet, with padding

A bad variant value raises a Lua error. The decode functions use the recoverable error shape. See globals Error shapes.

encode

geode.utils.base64.encode(data: string, variant: number?) -> string

Encodes a string into base64. The default variant is UrlWithPad.

decode

geode.utils.base64.decode(data: string, variant: number?) -> (string?, string?)

Decodes base64 into raw bytes, returned as a Luau string. Whitespace is skipped. Decoding stops at the first NUL byte or = padding marker. Padding is ignored for Normal, which behaves like NormalNoPad. Returns the bytes, or nil and an error message. The default variant is Url.

decodeString

geode.utils.base64.decodeString(data: string, variant: number?) -> (string?, string?)

Same bytes as decode, returned as a Luau string. Does not validate that the result is valid UTF-8 text.

Variant

geode.utils.base64.Variant -> { Normal: number, NormalNoPad: number, Url: number, UrlWithPad: number }

A table of the variant values.

Example

local b64 = geode.utils.base64

local text = b64.encode("hello", b64.Variant.UrlWithPad)
local back, err = b64.decodeString(text, b64.Variant.UrlWithPad)
if not back then return print(err) end
print(back) -- hello

Related

Source

  • src/bindings/geode/GeodeSmallBindings.cpp