Base64 → Methods

Encode & Decode

Four methods covering raw string encoding and table encoding. Use the raw pair for binary data; use the table pair when you need to round-trip a Luau table through a string (DataStore, URL param, or route response body).

Signatures

Base64.Encode(data: string) → string
Base64.Decode(data: string) → string
Base64.EncodeTable(tbl: \{\}) → string
Base64.DecodeTable(data: string) → \{\}

Raw string methods

Encode converts any binary string to a Base64-encoded ASCII string safe for transport through RemoteEvent and JSON. Decode reverses the operation and returns the original binary string.

local Base64 = RoExpress.Base64

local binary  = "\0\1\2\3\255"   -- raw binary with null bytes
local encoded = Base64.Encode(binary)
local decoded = Base64.Decode(encoded)
print(decoded == binary)              -- true

Table methods

EncodeTable JSON-encodes the table then Base64-encodes the resulting string. DecodeTable reverses the process and returns a Luau table. Useful for storing structured data as a single DataStore string entry.

local Base64 = RoExpress.Base64

-- Encode/decode a table
local str = Base64.EncodeTable({ items = { 1, 2, 3 }, score = 42 })
local tbl = Base64.DecodeTable(str)
print(tbl.score)   -- 42

When to use Base64 directly

You rarely need Base64 directly. Codec handles compression and encoding internally, and Stream handles all binary serialisation. Use Base64 manually only when:

  • You need to transport raw binary data through a standard res:Send() response.
  • You are storing binary blobs as strings in DataStore without compression.
  • You need a URL-safe encoding of arbitrary data in a route param or query string.

See also

← Base64  ·  Codec | LZ77/LZH compression (uses Base64 internally)  ·  Stream | typed binary channels  ·  Response Object | res:Send() response body