Documentation
¶
Overview ¶
Package base64 implements the base64 codec (RFC 4648) without the Go standard library.
It exists because `encoding/base64` costs a measured 18,740 bytes in a TinyGo wasm binary — real weight on the edge (Cloudflare Workers, goflare) for a transformation that is a lookup table and some bit shifting. The stdlib is TinyGo-compatible; this package is about size, not compatibility.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalid error = invalidError{}
ErrInvalid is returned for any input that is not well-formed base64.
Functions ¶
func Decode ¶ added in v0.0.4
Decode decodes a padded standard base64 string (RFC 4648 §4), equivalent to the stdlib's StdEncoding.Strict(). Padding is required and its length must match the trailing group size; any '=' outside the final group — or any byte outside the standard alphabet — is rejected via the same canonicality rule URLDecode applies.
func Encode ¶ added in v0.0.4
Encode encodes src as standard base64 (RFC 4648 §4) WITH padding — equivalent to the stdlib's StdEncoding. This is what data URIs, MCP image content, and most JSON/HTTP payloads expect; use URLEncode instead for tokens embedded in a URL or a JWT segment.
func URLDecode ¶ added in v0.0.2
URLDecode decodes an unpadded base64url string.
Every byte outside the alphabet is rejected, including '=', '+', '/' and whitespace, and so is any non-canonical encoding (RFC 4648 §3.5: the unused trailing bits of the final group must be zero). This decodes tokens, so leniency would mean accepting a signature segment the signer never produced. It is equivalent to the stdlib's RawURLEncoding.Strict() — deliberately stricter than the stdlib default, which accepts non-canonical input.
Types ¶
This section is empty.