base64

package
v0.4.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2026 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package base64 is the "encoding/base64" host module: base64 lives under std/encoding rather than in std's own flat root because it, like its eight siblings, uses none of std's shared sandbox/exec helpers (resolvePath, checkRead, checkWrite, optStringDefault, ...) - every helper a text codec needs is local to its own file, so splitting it into its own package hides nothing that std itself needs to reach back into. See std/encoding/register.go for how this directory's Module reaches the rest of magus without std importing back down to collect it (that would cycle: std/encoding imports std for the Module vocabulary already).

Index

Constants

This section is empty.

Variables

View Source
var Module = std.Module{
	Name: "base64",
	WASM: true,
	Path: "encoding/base64",
	Doc:  "Base64 text codec (standard and URL-safe, both padded).",
	Methods: []std.Method{
		{
			Name:    "encode",
			Doc:     "Encode data as standard (padded) base64.",
			Args:    []std.Arg{{Name: "data", Type: std.TypeString}},
			Returns: []std.Ret{{Type: std.TypeString}},
			Impl:    Base64Encode,
		},
		{
			Name:    "decode",
			Doc:     "Decode a standard (padded) base64 string; errors on malformed input.",
			Args:    []std.Arg{{Name: "s", Type: std.TypeString}},
			Returns: []std.Ret{{Type: std.TypeString}},
			Raises:  true,
			Impl:    Base64Decode,
		},
		{
			Name:    "url_encode",
			Doc:     "Encode data as URL-safe (padded) base64.",
			Args:    []std.Arg{{Name: "data", Type: std.TypeString}},
			Returns: []std.Ret{{Type: std.TypeString}},
			Impl:    Base64URLEncode,
		},
		{
			Name:    "url_decode",
			Doc:     "Decode a URL-safe (padded) base64 string; errors on malformed input.",
			Args:    []std.Arg{{Name: "s", Type: std.TypeString}},
			Returns: []std.Ret{{Type: std.TypeString}},
			Raises:  true,
			Impl:    Base64URLDecode,
		},
	},
}

Module is the "encoding/base64" host module. Buzz's own stdlib hashes (crypto.hash) and serializes JSON but has no general-purpose binary-to-text codec, so a spell that signs a request or embeds a blob in a config would otherwise have to reimplement base64 in script.

Inputs and outputs are plain strings: bytes cross as their raw string content (Buzz strings are byte-preserving for ASCII/UTF-8 payloads), the same shape crypto.*_hex consumes. crypto.base64Encode is the byte-list form for genuinely binary data.

Functions

func Base64Decode

func Base64Decode(_ context.Context, s string) (string, error)

Base64Decode decodes a standard padded base64 string.

func Base64Encode

func Base64Encode(_ context.Context, data string) (string, error)

Base64Encode encodes data as standard padded base64.

func Base64URLDecode

func Base64URLDecode(_ context.Context, s string) (string, error)

Base64URLDecode decodes a URL-safe padded base64 string.

func Base64URLEncode

func Base64URLEncode(_ context.Context, data string) (string, error)

Base64URLEncode encodes data as URL-safe padded base64.

func Modules

func Modules() []std.Module

Modules returns this directory's contribution to the encoding module set. See std/encoding/register.go: it aggregates every leaf's Modules() into one slice, which is how a module here reaches std.All()'s callers without std importing this package to collect it.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL