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}- wheremediatypeis 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}- wheremediatypeis the MIME type ("text/plain"by default),charsetthe encoding of the payload ornil, andpayload_encodingis one of:urlencor:base64{:error, reason}