Reqord.Storage.Behavior behaviour (reqord v0.4.0)
View SourceBehavior for storage backends.
This module defines the interface that all storage backends must implement, allowing for pluggable storage solutions (FileSystem, S3, Redis, etc.).
Summary
Callbacks
Delete an entire cassette file.
Delete an external object by its hash.
Ensure the path directory structure exists.
Check if a cassette exists at the specified path.
List all stored objects (for maintenance tasks).
Load a binary object by its hash reference.
Load streaming data chunks by hash reference.
Stream all entries from the specified cassette path.
Store a binary object externally and return its reference.
Store streaming data chunks externally.
Write a single entry to the specified cassette path.
Callbacks
Delete an entire cassette file.
Parameters
path- The cassette path/identifier
Returns
:okon success (also returns :ok if file doesn't exist){:error, reason}on failure
Delete an external object by its hash.
Parameters
hash- Object hash identifier
Returns
:okon success (also returns :ok if object doesn't exist){:error, reason}on failure
Ensure the path directory structure exists.
Parameters
path- The cassette path whose directory structure should exist
Returns
:okon success{:error, reason}on failure
Check if a cassette exists at the specified path.
Parameters
path- The cassette path/identifier
Returns
trueif the cassette existsfalseotherwise
List all stored objects (for maintenance tasks).
Returns
{:ok, hashes}with list of object hash identifiers{:error, reason}on failure
Load a binary object by its hash reference.
Parameters
hash- Object hash identifier
Returns
{:ok, content}on success with the binary content{:error, reason}on failure (e.g., object not found)
Load streaming data chunks by hash reference.
Parameters
hash- Stream hash identifier
Returns
{:ok, chunks}on success with list of {timestamp, data} tuples{:error, reason}on failure
@callback read_entries(path :: String.t()) :: Enumerable.t()
Stream all entries from the specified cassette path.
Parameters
path- The cassette path/identifier
Returns
- An Enumerable that yields entry maps
@callback store_object(hash :: String.t(), content :: binary()) :: {:ok, String.t()} | {:error, term()}
Store a binary object externally and return its reference.
Parameters
hash- Content hash to use as the object identifiercontent- Binary content to store
Returns
{:ok, hash}on success with the object hash{:error, reason}on failure
@callback store_stream(hash :: String.t(), chunks :: list()) :: {:ok, String.t()} | {:error, term()}
Store streaming data chunks externally.
Parameters
hash- Content hash to use as the stream identifierchunks- List of {timestamp, data} tuples representing stream chunks
Returns
{:ok, hash}on success with the stream hash{:error, reason}on failure
Write a single entry to the specified cassette path.
Parameters
path- The cassette path/identifierentry- The entry data as a map
Returns
:okon success{:error, reason}on failure