@eryx/encoding/base64 Module

JSON

Base64 encoding utilities.

Encodes binary buffer data into the standard Base64 alphabet (RFC 4648). A custom alphabet may be supplied for URL-safe or other variants.

local base64 = require("@eryx/base64")
local encoded = base64.encode(buffer.fromstring("Hello, world!"))
print(encoded) -- "SGVsbG8sIHdvcmxkIQ=="

Summary

Functions

base64.encode(data: buffer, alphabet: string?)string
base64.decode(str: string, alphabet: string?)buffer

API Reference

Functions

base64.encode

Encodes a buffer into a Base64 string.

Uses the standard Base64 alphabet by default. Pass a custom 64-character alphabet string to use a different encoding (e.g. URL-safe Base64 with "-_" instead of "+/").

base64.encode(data: buffer, alphabet: string?)string

Parameters

data: buffer

The binary data to encode.

alphabet: string?

A custom 64-character alphabet string.

Returns

string

The Base64-encoded string.

base64.decode

Decodes a Base64 string back into a buffer.

Uses the standard Base64 alphabet by default. Pass the same custom alphabet that was used for encoding to decode URL-safe or other variants.

base64.decode(str: string, alphabet: string?)buffer

Parameters

str: string

The Base64-encoded string.

alphabet: string?

A custom 64-character alphabet string.

Returns

buffer

The decoded binary data.

Constants