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 RFC 2397 |
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 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}