jhn_base (jhn_stdlib v5.12.2)

View Source

A binary data encodinglibrary providing support for a number of bases, algorithms and alphabets. If nothing else is specified the "standard" algorithm is used . The algorithm and alphabet to use in encoding or decoding can be specified with options provided to encode/3 and decode/3. Further options are the for the return values of either an iolist or binary, with the exception of the Z-Base-32 algorithm that returns a bitstring.

The following documents are the base for the library

rfc4648: The Base16, Base32, and Base64 Data Encodings * Base32 standard algorithm (standard) * Base32 standard and hex alphabets (standard, hex)

The Base32 wikipage: https://en.wikipedia.org/wiki/Base32 * The Geohash alphabet (geohash)

Crockford's Base32: https://datatracker.ietf.org/doc/draft-crockford-davis-base32-for-humans/ * Crockford base32 algorithm (crockford)

Clockwork: https://github.com/szktty/go-clockwork-base32 * The clockwork algorithm (clockwork)

Z-Base-32: https://philzimmermann.com/docs/human-oriented-base-32-encoding.txt * The Z-Base-32 algorithm (zbase) Does not support binary/iolist deoding since it returns a bitstring only

rfc9285: The Base45 Data Encoding * Base 45 standard algorithm (standard)

The Base58 Encoding Scheme (Bitcoin): https://datatracker.ietf.org/doc/html/draft-msporny-base58-03 * Base58 standard algorithm (standard) * Base58 standard alphabet (standard)

The Flickr Base58 alphabet https://www.flickr.com/groups/51035612836@N01/discuss/72157616713786392/ * Base58 flickr alphabet (flickr)

The Ripple Base58 alphabet https://xrpl.org/docs/references/protocol/data-types/base58-encodings * Base58 Ripple alphabet (ripple)

Ascii85: https://en.wikipedia.org/wiki/Ascii85 * The Base85 algorithm

ZeroMQ spec:32/Z85: https://rfc.zeromq.org/spec/32/ * The ZeroMQ base85 algorithm (z85)

rfc1924: A Compact Representation of IPv6 Addresses * The rfc1924 algorithm (ipv6) uses jhn_ip_addr to decode the address

Summary

Functions

Decodes the data as an iolist using Base default algorithm and alphabet, equivalent to decode(Base, Encoded, []).

Decodes the data as an iolist, bitstring or binary according to the Base. Options binary : returns a binary, not viable for Z-Base-32 iolist : returns an iolist (default) {return_type, binary | iolist}: returns what is specified {algo, Algo}: uses the algorithm Algo for decoding {alphabet, A}: uses the alphabet for the decoding, must be compatible with the algorithm (no checks are done).

Encodes the data as an iolist using Base default algorithm and alphabet, equivalent to encode(Base, Data, []).

Encodes the data as an iolist or binary according to the Base. Options binary : returns a binary, iolist : returns an iolist (default) {return_type, binary | iolist}: returns what is specified {algo, Algo}: uses the algorithm Algo for encoding {alphabet, A}: uses the alphabet for the encoding, must be compatible with the algorithm (no checks are done).

Types

algo/0

-type algo() :: standard | crockford | clockwork | zbase | z85 | ipv6.

alphabet/0

-type alphabet() :: standard | hex | geohash | flickr | ripple.

base/0

-type base() :: 32 | 45 | 58 | 85.

opt/0

-type opt() :: return_type() | {return_type, return_type()} | {alpfabet, alphabet()} | {algo, algo()}.

return_type/0

-type return_type() :: iolist | binary.

Functions

decode(Base, Data)

-spec decode(base(), iodata()) -> iolist() | bitstring().

Decodes the data as an iolist using Base default algorithm and alphabet, equivalent to decode(Base, Encoded, []).

decode(Base, Data, Opts)

-spec decode(base(), iodata(), [opt()]) -> iolist() | bitstring().

Decodes the data as an iolist, bitstring or binary according to the Base. Options binary : returns a binary, not viable for Z-Base-32 iolist : returns an iolist (default) {return_type, binary | iolist}: returns what is specified {algo, Algo}: uses the algorithm Algo for decoding {alphabet, A}: uses the alphabet for the decoding, must be compatible with the algorithm (no checks are done).

encode(Base, Data)

-spec encode(base(), iodata()) -> iolist().

Encodes the data as an iolist using Base default algorithm and alphabet, equivalent to encode(Base, Data, []).

encode(Base, Data, Opts)

-spec encode(base(), iodata() | bitstring(), [opt()]) -> iolist().

Encodes the data as an iolist or binary according to the Base. Options binary : returns a binary, iolist : returns an iolist (default) {return_type, binary | iolist}: returns what is specified {algo, Algo}: uses the algorithm Algo for encoding {alphabet, A}: uses the alphabet for the encoding, must be compatible with the algorithm (no checks are done).