FileStore (file_store v0.2.1)

FileStore allows you to read, write, upload, download, and interact with files, regardless of where they are stored.

Adapters

This package ships with the following adapters:

The documentation for each adapter includes an example that demonstrates it's usage.

Link to this section Summary

Functions

Delete a file from the store.

Download a file from the store and save it to the given path.

Get URL for your file, assuming that the file is publicly accessible.

Generate a signed URL for your file. Any user with this URL should be able to access the file.

List all of the files in the store.

Configures a new store.

Read the contents of a file in store into memory.

Retrieve information about a file from the store.

Upload a file to the store. If a file with the given key already exists, it will be overwritten.

Write a file to the store. If a file with the given key already exists, it will be overwritten.

Link to this section Types

Specs

key() :: binary()

Specs

path() :: Path.t()

Specs

t() :: %FileStore{adapter: module(), config: map()}

Specs

url() :: binary()

Link to this section Functions

Link to this function

delete(store, key)

Specs

delete(t(), key()) :: :ok | {:error, term()}

Delete a file from the store.

Examples

iex> FileStore.delete(store, "foo") :ok

Link to this function

download(store, key, destination)

Specs

download(t(), key(), path()) :: :ok | {:error, term()}

Download a file from the store and save it to the given path.

Examples

iex> FileStore.download(store, "foo", "/path/to/bar.txt")
:ok
Link to this function

get_public_url(store, key, opts \\ [])

Specs

get_public_url(t(), key(), keyword()) :: url()

Get URL for your file, assuming that the file is publicly accessible.

Examples

iex> FileStore.get_public_url(store, "foo")
"https://mybucket.s3-us-east-1.amazonaws.com/foo"
Link to this function

get_signed_url(store, key, opts \\ [])

Specs

get_signed_url(t(), key(), keyword()) :: {:ok, url()} | {:error, term()}

Generate a signed URL for your file. Any user with this URL should be able to access the file.

Examples

iex> FileStore.get_signed_url(store, "foo")
{:ok, "https://s3.amazonaws.com/mybucket/foo?X-AMZ-Expires=3600&..."}

Specs

list!(t()) :: Enumerable.t()

List all of the files in the store.

Examples

iex> Enum.to_list(FileStore.list!(store))
["foo/bar"]

Specs

new(keyword()) :: t()

Configures a new store.

Examples

iex> FileStore.new(adapter: FileStore.Adapters.Memory)
%FileStore{adapter: FileStore.Adapters.Memory, config: %{}}
Link to this function

read(store, key)

Specs

read(t(), key()) :: {:ok, binary()} | {:error, term()}

Read the contents of a file in store into memory.

Examples

iex> FileStore.read(store, "foo")
{:ok, "hello world"}
Link to this function

stat(store, key)

Specs

stat(t(), key()) :: {:ok, FileStore.Stat.t()} | {:error, term()}

Retrieve information about a file from the store.

Examples

iex> FileStore.stat(store, "foo")
{:ok, %FileStore.Stat{key: "foo", etag: "2e5pd429", size: 24}}
Link to this function

upload(store, source, key)

Specs

upload(t(), path(), key()) :: :ok | {:error, term()}

Upload a file to the store. If a file with the given key already exists, it will be overwritten.

Examples

iex> FileStore.upload(store, "/path/to/bar.txt", "foo")
:ok
Link to this function

write(store, key, content)

Specs

write(t(), key(), binary()) :: :ok | {:error, term()}

Write a file to the store. If a file with the given key already exists, it will be overwritten.

Examples

iex> FileStore.write(store, "foo", "hello world")
:ok