View Source Entrepot.Storage behaviour (Bonfire v0.9.11-social-beta.6)

A behaviour module defining the interface for storage backends.

This module specifies the callbacks that must be implemented by any storage backend used with Entrepôt.

Summary

Callbacks

Deletes a file from the storage backend.

Retrieves the local filesystem path of the stored file, if applicable.

Stores a file in the storage backend.

Reads the contents of the stored file.

Creates a stream for reading the contents of the stored file.

Generates a URL for accessing the stored file.

Types

locator_id()

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

option()

@type option() :: {atom(), any()}

Callbacks

delete(locator_id)

@callback delete(locator_id()) :: :ok | {:error, String.t()}

delete(locator_id, list)

@callback delete(locator_id(), [option()]) :: :ok | {:error, String.t()}

Deletes a file from the storage backend.

Parameters

  • locator_id: The unique identifier of the file to be deleted.
  • opts: Optional list of options.

Returns

  • :ok: If the file was successfully deleted.
  • {:error, String.t()}: An error message if the file cannot be deleted.

path(locator_id)

@callback path(locator_id()) :: binary() | nil

path(locator_id, list)

@callback path(locator_id(), [option()]) :: binary() | nil

Retrieves the local filesystem path of the stored file, if applicable.

Parameters

  • locator_id: The unique identifier of the stored file.
  • opts: Optional list of options.

Returns

  • binary(): The local filesystem path of the file.
  • nil: If a local path is not applicable or available.

put(t)

@callback put(Entrepot.Upload.t()) :: {:ok, locator_id()} | {:error, String.t()}

put(t, list)

@callback put(Entrepot.Upload.t(), [option()]) ::
  {:ok, locator_id()} | {:error, String.t()}

Stores a file in the storage backend.

Parameters

  • upload: An Upload struct representing the file to be stored.
  • opts: Optional list of options.

Returns

  • {:ok, locator_id}: The unique identifier of the stored file.
  • {:error, String.t()}: An error message if the file cannot be stored.

read(locator_id)

@callback read(locator_id()) :: {:ok, binary()} | {:error, String.t()}

read(locator_id, list)

@callback read(locator_id(), [option()]) :: {:ok, binary()} | {:error, String.t()}

Reads the contents of the stored file.

Parameters

  • locator_id: The unique identifier of the stored file.
  • opts: Optional list of options.

Returns

  • {:ok, binary()}: The contents of the file.
  • {:error, String.t()}: An error message if the file cannot be read.

stream(locator_id)

@callback stream(locator_id()) :: IO.Stream.t() | File.Stream.t() | Stream.t()

stream(locator_id, list)

@callback stream(locator_id(), [option()]) :: IO.Stream.t() | File.Stream.t() | Stream.t()

Creates a stream for reading the contents of the stored file.

Parameters

  • locator_id: The unique identifier of the stored file.
  • opts: Optional list of options.

Returns

  • IO.Stream.t() | File.Stream.t() | Stream.t(): A stream for reading the file contents.

url(locator_id)

@callback url(locator_id()) :: binary() | nil

url(locator_id, list)

@callback url(locator_id(), [option()]) :: binary() | nil

Generates a URL for accessing the stored file.

Parameters

  • locator_id: The unique identifier of the stored file.
  • opts: Optional list of options.

Returns

  • binary(): The URL for accessing the file.
  • nil: If a URL cannot be generated.