Attached.StorageBackends.Behaviour behaviour (Attached v0.1.1)

Copy Markdown View Source

Behaviour contract for storage backends.

Implement this behaviour to add a new backend. Callers should not use the backend module directly — go through Attached.StorageBackends (which dispatches to the configured backend).

Summary

Callbacks

Concatenate files at source_keys into a single file at destination_key.

Delete the file at key.

Delete files at keys starting with the prefix.

Download the file at key and return its binary content.

Return the partial content in the byte range of the file at key.

Return true if a file exists at key.

Upload a file from source_path to the given key.

Return a URL for the file at key.

Types

key()

@type key() :: String.t()

Callbacks

compose(source_keys, destination_key)

@callback compose(source_keys :: [key()], destination_key :: key()) ::
  :ok | {:error, term()}

Concatenate files at source_keys into a single file at destination_key.

delete(key)

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

Delete the file at key.

delete_prefixed(prefix)

@callback delete_prefixed(prefix :: String.t()) :: :ok | {:error, term()}

Delete files at keys starting with the prefix.

download(key)

@callback download(key()) :: {:ok, binary()} | {:error, term()}

Download the file at key and return its binary content.

download_chunk(key, t)

@callback download_chunk(key(), Range.t()) :: {:ok, binary()} | {:error, term()}

Return the partial content in the byte range of the file at key.

exists?(key)

@callback exists?(key()) :: boolean()

Return true if a file exists at key.

upload(key, source_path, opts)

@callback upload(key(), source_path :: String.t(), opts :: keyword()) ::
  :ok | {:error, term()}

Upload a file from source_path to the given key.

url(key, opts)

@callback url(key(), opts :: keyword()) :: String.t()

Return a URL for the file at key.