A disk is a plain value that describes where files are stored.
Build one with Fil.disk/1 (short for new/1) and pass it around. There's no global configuration, no registry and
no process behind it:
disk = Fil.disk(adapter: Fil.Adapter.Local, root: "priv/storage")The struct holds the adapter module together with the state its Fil.Adapter.init/1 returned, and the plugins
attached with Fil.attach/4 or the :plugins option of new/1. The adapter state may contain
credentials, so %Fil.Disk{} has a custom Inspect implementation that prints only the adapter label:
iex> inspect(Fil.disk(adapter: Fil.Adapter.Local, root: "/tmp/fil"))
"#Fil.Disk<local>"Refs and errors contain the disk too. Logging them is safe, because logs use inspect, but anything that stores the
raw term (:erlang.term_to_binary/1, a crash dump) stores the credentials with it.
Summary
Functions
Returns the adapter module backing disk.
A short, human readable label for the disk's adapter.
Builds a disk. Fil.disk/1 is the same function.
Types
@type t() :: %Fil.Disk{ adapter: {module(), term()}, plugins: [{atom(), Fil.plugin_callback(), keyword()}] }
Functions
Returns the adapter module backing disk.
iex> Fil.Disk.adapter(Fil.disk(adapter: Fil.Adapter.Local, root: "/tmp/fil"))
Fil.Adapter.Local
A short, human readable label for the disk's adapter.
Used by the Inspect implementations of Fil.Disk and Fil.Ref.
iex> Fil.Disk.label(Fil.disk(adapter: Fil.Adapter.Local, root: "/tmp/fil"))
"local"
Builds a disk. Fil.disk/1 is the same function.
iex> Fil.Disk.new(adapter: Fil.Adapter.Local, root: "/tmp/fil")
#Fil.Disk<local>The adapter validates its options here, once. Invalid options raise ArgumentError when the disk is built instead of
failing on first use.
Options
:adapter(atom/0) - Required. The adapter module. Every option other than:adapterand:pluginsis passed to the adapter, which validates it against its own schema.:plugins(list of tuple ofatom/0,atom/0,keyword/0values) - Plugins to attach, in order, so the first one is the outermost. Each is a plugin callback as{module, function, opts}, attached under the namemodule(seeFil.attach/4). They're plain data, so the plugins can come from config along with the adapter options:plugins: [{Fil.Plugin.ContentType, :call, default: "text/plain"}]. The default value is[].