Base64 Utilities

Base64 Utilities

Base64 encoding and decoding with URL-safe variants:

Functions

sandman.base64.try_decode

Type: Function
Description: Decodes a base64 string

⚠️ Note: This function can throw errors. A sandman.base64.try_decode alternative is available that returns result_or_nil, error instead of throwing.

Usage

data = sandman.base64.decode(b64_string)

Parameters

  • b64_string: string

Returns

  • data: string

Examples

-- Basic usage
data = sandman.base64.decode(b64_string)

-- Safe alternative (returns data_or_nil, error):
data_or_nil, error = sandman.base64.try_decode(b64_string)
if data_or_nil then
  -- Use data_or_nil
else
  -- Handle the error
end

sandman.base64.encode

Type: Function
Description: Encodes a string to base64

Usage

b64_string = sandman.base64.encode(data)

Parameters

  • data: string

Returns

  • b64_string: string

Examples

-- Basic usage
b64_string = sandman.base64.encode(data)

sandman.base64.try_decode_url

Type: Function
Description: Decodes a URL-safe base64 string

⚠️ Note: This function can throw errors. A sandman.base64.try_decode_url alternative is available that returns result_or_nil, error instead of throwing.

Usage

data = sandman.base64.decode_url(b64_string)

Parameters

  • b64_string: string

Returns

  • data: string

Examples

-- Basic usage
data = sandman.base64.decode_url(b64_string)

-- Safe alternative (returns data_or_nil, error):
data_or_nil, error = sandman.base64.try_decode_url(b64_string)
if data_or_nil then
  -- Use data_or_nil
else
  -- Handle the error
end

sandman.base64.encode_url

Type: Function
Description: Encodes a string to URL-safe base64

Usage

b64_string = sandman.base64.encode_url(data)

Parameters

  • data: string

Returns

  • b64_string: string

Examples

-- Basic usage
b64_string = sandman.base64.encode_url(data)