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:

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}
parse(arg1)

Specs:

Parse a RFC 2397 URI.

Return values:

  • {:ok, mediatype, data} - where mediatype is the one given in the metadata, or "text/plain" if it’s omitted;
  • {:error, reason}
parse_metadata(metadata)

Specs:

Only parse metadata of an RFC 2397 URI.

Return values:

  • {:ok, mediatype, charset, payload_encoding} - where mediatype is the MIME type ("text/plain" by default), charset the encoding of the payload or nil, and payload_encoding is one of :urlenc or :base64
  • {:error, reason}