resx v0.0.4 Resx.Producers.Data
A producer to handle data URIs.
Resx.Producers.Data.open("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ%3D%3D")
Media Types
If an error is being returned when attempting to open a data URI due to { :invalid_reference, "invalid media type: #{type}" }
, the MIME type will need to be added to the config.
Attributes
Data URI attributes will be able to be accessed as resource attributes Resx.Resource.attributes/1
Link to this section Summary
Functions
Manually create a data resource
Link to this section Functions
new(Resx.Resource.t() | binary(), type: String.t(), attributes: %{optional(Resx.Resource.attribute_key()) => any()} ) :: {:ok, Resx.Resource.t()} | Resx.error(Resx.resource_error() | Resx.reference_error())
Manually create a data resource.
Converts the static resource state or a binary into a data resource.
The type defaults to an "application/octet-stream"
or the parent type of the existing resource. This can be overridden by explicitly passing a type to the :type
option.
No attributes are attached to the data resource by default. This can be overridden by passing the attributes to the :attributes
option.
iex> { :ok, resource } = Resx.Producers.Data.new("hello")
...> resource.content
%Resx.Resource.Content{ data: "hello", type: ["application/octet-stream"] }
iex> { :ok, resource } = Resx.Producers.Data.new("hello", type: "text/plain")
...> resource.content.type
["text/plain"]
iex> { :ok, resource } = Resx.Producers.Data.new("hello")
...> Resx.Resource.attribute(resource, "charset")
{ :error, { :unknown_key, "charset" } }
iex> { :ok, resource } = Resx.Producers.Data.new("hello", attributes: %{ "charset" => "US-ASCII" })
...> Resx.Resource.attribute(resource, "charset")
{ :ok, "US-ASCII" }