One call to a Fil function, as plugins see it.
Every operation builds a %Fil.Op{} and passes it through the disk's plugins to the adapter. See the
Plugins guide for how to write a plugin.
:disk: theFil.Diskthe operation runs on:name: the operation,:read,:write,:stat,:ls,:rm,:rm_rf,:cp,:rename,:urlor:signed_url:path: the normalized path, relative to the disk root:dest: the destination path of a:cpor:renameon the same disk,nilotherwise:content: the content of a:write,nilotherwise. Change it withupdate_content/2:options: the validated options of the call:result:nilon the way in, then{:ok, value}or{:error, exception}with the same value theFilfunction returns. Change a read result withupdate_result/2:private: a map for plugins to pass data along
Summary
Functions
Returns an option of the call.
Returns a private value.
Makes the content of a :write whole, for plugins that need all of it at once.
Sets an option unless the call already has it.
Sets an option before the adapter sees it.
Stores a private value, for a later plugin or for the way back.
Sets the result.
Transforms the content of a :write. Other operations are returned unchanged.
Transforms the content returned by a successful :read. Other operations and errors are returned unchanged.
Types
@type name() ::
:read
| :write
| :stat
| :ls
| :rm
| :rm_rf
| :cp
| :rename
| :url
| :signed_url
@type t() :: %Fil.Op{ content: iodata() | nil, dest: Path.t() | nil, disk: Fil.Disk.t(), name: name(), options: keyword(), path: Path.t(), private: map(), result: {:ok, term()} | {:error, Exception.t()} | nil }
Functions
Returns an option of the call.
iex> op = %Fil.Op{disk: nil, name: :write, path: "a.txt", options: [content_type: "text/plain"]}
iex> Fil.Op.get_option(op, :content_type)
"text/plain"
iex> Fil.Op.get_option(op, :missing, :default)
:default
Returns a private value.
iex> op = %Fil.Op{disk: nil, name: :read, path: "a.txt"}
iex> Fil.Op.get_private(op, :seen, false)
false
Makes the content of a :write whole, for plugins that need all of it at once.
Content is always whole for now, so this only flattens iodata into a binary. Once streaming lands, it collects a stream into memory, so use it only when a plugin can't work chunk by chunk.
iex> op = %Fil.Op{disk: nil, name: :write, path: "a.txt", content: ["a", ["b"]]}
iex> Fil.Op.materialize(op).content
"ab"
Sets an option unless the call already has it.
iex> op = %Fil.Op{disk: nil, name: :write, path: "a.txt", options: [content_type: "text/plain"]}
iex> op |> Fil.Op.put_new_option(:content_type, "text/csv") |> Fil.Op.get_option(:content_type)
"text/plain"
Sets an option before the adapter sees it.
iex> op = %Fil.Op{disk: nil, name: :write, path: "a.txt", options: [content_type: "text/plain"]}
iex> op |> Fil.Op.put_option(:content_type, "text/csv") |> Fil.Op.get_option(:content_type)
"text/csv"
Stores a private value, for a later plugin or for the way back.
iex> op = %Fil.Op{disk: nil, name: :read, path: "a.txt"}
iex> op |> Fil.Op.put_private(:seen, true) |> Fil.Op.get_private(:seen)
true
@spec put_result(t(), {:ok, term()} | {:error, Exception.t()}) :: t()
Sets the result.
A plugin that sets the result instead of calling next answers the call itself, and the adapter never runs. An error
is an exception: one of Fil's (see Errors) or the plugin's own. Fil fills in
the :op, :path and :disk of its own errors where the plugin left them nil.
Transforms the content of a :write. Other operations are returned unchanged.
Pass binary: to transform the whole content at once and chunk: to transform it piece by piece:
Fil.Op.update_content(op, binary: &:zlib.gzip/1)Content is always whole for now, so binary: runs and gets a binary (iodata is flattened first). Without binary:,
the content is passed to chunk: as a single chunk. Once streaming lands, chunk: runs on each chunk of a stream,
and a stream is collected first if there's only binary:.
Transforms the content returned by a successful :read. Other operations and errors are returned unchanged.
Takes the same binary: and chunk: functions as update_content/2.