Depot v0.2.1 Depot View Source
Depot is a filesystem abstraction for elixir providing a unified interface over many implementations. It allows you to swap out filesystems on the fly without needing to rewrite all of your application code in the process. It can eliminate vendor-lock in, reduce technical debt, and improve the testability of your code.
This library is based on the ideas of flysystem, which is a PHP library providing similar functionality.
Examples
defmodule LocalFileSystem do
use Depot.Filesystem,
adapter: Depot.Adapter.Local,
prefix: prefix
end
LocalFileSystem.write("test.txt", "Hello World")
{:ok, "Hello World"} = LocalFileSystem.read("test.txt")
Link to this section Summary
Functions
Copy a file from source to destination on a filesystem
Delete a file from a filesystem
Copy a file from source to destination on a filesystem
List the contents of a folder on a filesystem
Move a file from source to destination on a filesystem
Read from a filesystem
Write to a filesystem
Link to this section Types
Specs
adapter() :: module()
Specs
filesystem() :: {module(), Depot.Adapter.config()}
Link to this section Functions
Specs
copy(filesystem(), Path.t(), Path.t(), keyword()) :: :ok | {:error, term()}
Copy a file from source to destination on a filesystem
Examples
Direct filesystem
filesystem = Depot.Adapter.Local.configure(prefix: "/home/user/storage")
:ok = Depot.copy(filesystem, "test.txt", "other-test.txt")
Module-based filesystem
defmodule LocalFileSystem do
use Depot.Filesystem,
adapter: Depot.Adapter.Local,
prefix: "/home/user/storage"
end
:ok = LocalFileSystem.copy("test.txt", "other-test.txt")
Specs
delete(filesystem(), Path.t(), keyword()) :: :ok | {:error, term()}
Delete a file from a filesystem
Examples
Direct filesystem
filesystem = Depot.Adapter.Local.configure(prefix: "/home/user/storage")
:ok = Depot.delete(filesystem, "test.txt")
Module-based filesystem
defmodule LocalFileSystem do
use Depot.Filesystem,
adapter: Depot.Adapter.Local,
prefix: "/home/user/storage"
end
:ok = LocalFileSystem.delete("test.txt")
Specs
file_exists(filesystem(), Path.t(), keyword()) :: {:ok, :exists | :missing} | {:error, term()}
Copy a file from source to destination on a filesystem
Examples
Direct filesystem
filesystem = Depot.Adapter.Local.configure(prefix: "/home/user/storage")
:ok = Depot.copy(filesystem, "test.txt", "other-test.txt")
Module-based filesystem
defmodule LocalFileSystem do
use Depot.Filesystem,
adapter: Depot.Adapter.Local,
prefix: "/home/user/storage"
end
:ok = LocalFileSystem.copy("test.txt", "other-test.txt")
Specs
list_contents(filesystem(), Path.t(), keyword()) :: {:ok, [ %Depot.Stat.Dir{mtime: term(), name: term(), size: term()} | %Depot.Stat.File{mtime: term(), name: term(), size: term()} ]} | {:error, term()}
List the contents of a folder on a filesystem
Examples
Direct filesystem
filesystem = Depot.Adapter.Local.configure(prefix: "/home/user/storage")
{:ok, contents} = Depot.list_contents(filesystem, ".")
Module-based filesystem
defmodule LocalFileSystem do
use Depot.Filesystem,
adapter: Depot.Adapter.Local,
prefix: "/home/user/storage"
end
{:ok, contents} = LocalFileSystem.list_contents(".")
Specs
move(filesystem(), Path.t(), Path.t(), keyword()) :: :ok | {:error, term()}
Move a file from source to destination on a filesystem
Examples
Direct filesystem
filesystem = Depot.Adapter.Local.configure(prefix: "/home/user/storage")
:ok = Depot.move(filesystem, "test.txt", "other-test.txt")
Module-based filesystem
defmodule LocalFileSystem do
use Depot.Filesystem,
adapter: Depot.Adapter.Local,
prefix: "/home/user/storage"
end
:ok = LocalFileSystem.move("test.txt", "other-test.txt")
Specs
read(filesystem(), Path.t(), keyword()) :: {:ok, binary()} | {:error, term()}
Read from a filesystem
Examples
Direct filesystem
filesystem = Depot.Adapter.Local.configure(prefix: "/home/user/storage")
{:ok, "Hello World"} = Depot.read(filesystem, "test.txt")
Module-based filesystem
defmodule LocalFileSystem do
use Depot.Filesystem,
adapter: Depot.Adapter.Local,
prefix: "/home/user/storage"
end
{:ok, "Hello World"} = LocalFileSystem.read("test.txt")
Specs
write(filesystem(), Path.t(), iodata(), keyword()) :: :ok | {:error, term()}
Write to a filesystem
Examples
Direct filesystem
filesystem = Depot.Adapter.Local.configure(prefix: "/home/user/storage")
:ok = Depot.write(filesystem, "test.txt", "Hello World")
Module-based filesystem
defmodule LocalFileSystem do
use Depot.Filesystem,
adapter: Depot.Adapter.Local,
prefix: "/home/user/storage"
end
LocalFileSystem.write("test.txt", "Hello World")