magus v0.3.0 is out. See what's new
¶ View markdown source · ✎ Suggest an edit
2 min read

encoding

Base64/hex/URL text codecs.

Naming convention: import the module under its bare name (import "encoding"), reach members with a backslash, and call methods in camelCase: encoding\someMethod.

Methods

base64Encode

Encode data as standard (padded) base64.

Signature: encoding\base64Encode(data) → string1 · source

Parameter Type Optional Description
data string

Returns: string

base64Decode

Decode a standard (padded) base64 string; errors on malformed input.

Signature: encoding\base64Decode(s) → string · source

Parameter Type Optional Description
s string

Returns: string

base64urlEncode

Encode data as URL-safe (padded) base64.

Signature: encoding\base64urlEncode(data) → string · source

Parameter Type Optional Description
data string

Returns: string

base64urlDecode

Decode a URL-safe (padded) base64 string; errors on malformed input.

Signature: encoding\base64urlDecode(s) → string · source

Parameter Type Optional Description
s string

Returns: string

hexEncode

Encode data as lowercase hex.

Signature: encoding\hexEncode(data) → string2 · source

Parameter Type Optional Description
data string

Returns: string

hexDecode

Decode a hex string; errors on malformed input.

Signature: encoding\hexDecode(s) → string · source

Parameter Type Optional Description
s string

Returns: string

urlEncode

Percent-encode s for use in a URL query component.

Signature: encoding\urlEncode(s) → string · source

Parameter Type Optional Description
s string

Returns: string

urlDecode

Decode a percent-encoded URL query component; errors on malformed input.

Signature: encoding\urlDecode(s) → string · source

Parameter Type Optional Description
s string

Returns: string

parseUrl

Parse a URL string into {scheme, host, port, path, query, fragment}; errors on malformed input.

Signature: encoding\parseUrl(raw_url) → URL · source

Parameter Type Optional Description
raw_url string

Returns: map[string]any

buildUrl

Build a URL string from a URL object - the same shape parse_url returns, so the two round-trip. Missing fields are treated as empty.

Signature: encoding\buildUrl(parts) → string · source

Parameter Type Optional Description
parts map[string]any

Returns: string


  1. encoding\base64Encode is also in Buzz's standard library (str.encodeBase64 (built-in string method)); the magus form is sandbox-aware. ↩︎

  2. encoding\hexEncode is also in Buzz's standard library (str.hex (built-in string method)); the magus form is sandbox-aware. ↩︎

auto-generatedencodingmodulestdlibmagusfile
Last updated (63b34b40)
Earlier changes on this page (3)

Full history ↗ · Blame source ↗

Glossary

Magusfile

The magusfile.buzz that declares a project's targets (as export funs) and binds its spells. See targets.

Module

A magus stdlib namespace a magusfile imports for host capabilities: filesystem, exec, vcs, and more. See the module reference.

Buzz

The language magusfiles are written in (the .buzz engine). See engines.

Sandbox

The restricted filesystem and environment a target runs in, so builds stay reproducible and side-effect-free. See sandbox.

Conventions

This page uses none of the site's convention markers. The full set is on the conventions page.