ExDataURI
An Elixir parser and encoder for RFC 2397 URIs.
Usage:
iex> ExDataURI.parse("data:text/plain;base64,Zm9v")
{:ok, "text/plain", "foo"}
iex> ExDataURI.encode("foo")
{:ok, "data:text/plain;base64,Zm9v"}
Summary
encode(payload, mediatype \\ "text/plain", charset \\ nil, payload_encoding \\ :base64, input_charset \\ "utf8") | Create a RFC 2397 URI |
parse(arg1) | Parse a RFC 2397 URI |
parse_metadata(metadata) | Only parse metadata of an RFC 2397 URI |
Functions
encode(payload, mediatype \\ "text/plain", charset \\ nil, payload_encoding \\ :base64, input_charset \\ "utf8")
Specs:
- encode(bitstring, String.t, String.t | nil, :base64 | :urlenc, String.t) :: {:ok | :error, String.t}
Create a RFC 2397 URI.
payload_encoding
may be :base64
or :urlenc
.
charset
may be any charset supported by iconv, or nil
. If it’s nil
, the
payload is stored as-is (the default); if it’s not, use iconv to convert
payload from input_charset
to charset
.
Return values:
{:ok, uri}
{:error, reason}
Specs:
Parse a RFC 2397 URI.
Return values:
{:ok, mediatype, data}
- wheremediatype
is the one given in the metadata, or"text/plain"
if it’s omitted;{:error, reason}
Specs:
Only parse metadata of an RFC 2397 URI.
Return values:
{:ok, mediatype, charset, payload_encoding}
- wheremediatype
is the MIME type ("text/plain"
by default),charset
the encoding of the payload ornil
, andpayload_encoding
is one of:urlenc
or:base64
{:error, reason}