base (ex_stdlib v0.2.0)
View SourceBase encoding and decoding module.
This module provides functions for encoding and decoding data using various base encoding schemes: base16 (hex), base32, base64, and their URL-safe variants.
Examples:
Encoded = base:encode64("Hello, World!"),
Decoded = base:decode64(Encoded),
HexEncoded = base:encode16("binary data"),
UrlSafe = base:url_encode64("data with + and /").
Summary
Functions
Decodes Base16 (hexadecimal) encoded data.
Decodes Base16 (hexadecimal) encoded data with options.
Decodes standard Base32-encoded data.
Decodes standard Base32-encoded data with options.
Decodes Base64-encoded data.
Decodes Base64-encoded data with options.
Encodes binary data using Base16 (hexadecimal) encoding.
Encodes binary data using standard Base32 encoding.
Encodes binary data using Base64 encoding.
Decodes Base32 hex-encoded data.
Decodes Base32 hex-encoded data with options.
Encodes binary data using Base32 hex encoding.
Decodes URL-safe Base64-encoded data.
Decodes URL-safe Base64-encoded data with options.
Encodes binary data using URL-safe Base64 encoding.
Types
Functions
Decodes Base16 (hexadecimal) encoded data.
Accepts both uppercase and lowercase hexadecimal.
-spec decode16(binary() | string(), decode_options()) -> {ok, binary()} | error.
Decodes Base16 (hexadecimal) encoded data with options.
Options: - letter_case: mixed | upper | lower - expected case of hex digits Returns {ok, Decoded} on success, or error on invalid input.
Decodes standard Base32-encoded data.
Returns the decoded binary data. Raises an error if the input is invalid.
-spec decode32(binary() | string(), decode_options()) -> {ok, binary()} | error.
Decodes standard Base32-encoded data with options.
Returns {ok, Decoded} on success, or error on invalid input.
Decodes Base64-encoded data.
Returns the decoded binary data. Raises an error if the input is invalid.
-spec decode64(binary() | string(), decode_options()) -> {ok, binary()} | error.
Decodes Base64-encoded data with options.
Options: - ignore: whitespace | none - whether to ignore whitespace characters Returns {ok, Decoded} on success, or error on invalid input.
Encodes binary data using Base16 (hexadecimal) encoding.
Returns uppercase hexadecimal by default.
Encodes binary data using standard Base32 encoding.
Uses the standard Base32 alphabet (A-Z, 2-7) with padding.
Encodes binary data using Base64 encoding.
Returns a binary containing the Base64-encoded data with padding.
Decodes Base32 hex-encoded data.
Returns the decoded binary data. Raises an error if the input is invalid.
-spec hex_decode32(binary() | string(), decode_options()) -> {ok, binary()} | error.
Decodes Base32 hex-encoded data with options.
Returns {ok, Decoded} on success, or error on invalid input.
Encodes binary data using Base32 hex encoding.
Uses the extended hex alphabet (0-9, A-V) with padding.
Decodes URL-safe Base64-encoded data.
Handles both padded and unpadded URL-safe Base64.
-spec url_decode64(binary() | string(), decode_options()) -> {ok, binary()} | error.
Decodes URL-safe Base64-encoded data with options.
Returns {ok, Decoded} on success, or error on invalid input.
Encodes binary data using URL-safe Base64 encoding.
URL-safe Base64 uses '-' and '_' instead of '+' and '/', and omits padding.