ExZarr.Storage.Registry (ExZarr v1.1.0)
View SourceRegistry for managing storage backends.
The registry maintains a mapping of backend IDs to backend modules and provides functions for registering, querying, and using storage backends.
Built-in Backends
The following backends are registered by default:
:memory- In-memory storage (fast, non-persistent):filesystem- Local filesystem storage:zip- Zip archive storage
Registering Custom Backends
Via Configuration
Add to config/config.exs:
config :ex_zarr, :custom_storage_backends, [
MyApp.S3Storage,
MyApp.DatabaseStorage
]Programmatically
ExZarr.Storage.Registry.register(MyApp.S3Storage)At Application Start
defmodule MyApp.Application do
use Application
def start(_type, _args) do
# Register custom storage backends
ExZarr.Storage.Registry.register(MyApp.S3Storage)
# ... rest of supervision tree
end
endQuerying Backends
# Get a backend module
{:ok, module} = ExZarr.Storage.Registry.get(:s3)
# List all registered backend IDs
ids = ExZarr.Storage.Registry.list()
# Get backend information
{:ok, info} = ExZarr.Storage.Registry.info(:s3)
Summary
Functions
Returns a specification to start this module under a supervisor.
Gets a storage backend module by ID.
Gets information about a storage backend.
Lists all registered backend IDs.
Registers a custom storage backend module.
Starts the storage backend registry.
Unregisters a storage backend by ID.
Types
@type backend_id() :: atom()
@type backend_module() :: module()
@type registry_state() :: %{ backends: %{required(backend_id()) => backend_module()}, built_in: [backend_id()] }
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec get(backend_id()) :: {:ok, backend_module()} | {:error, :not_found}
Gets a storage backend module by ID.
Examples
iex> ExZarr.Storage.Registry.get(:filesystem)
{:ok, ExZarr.Storage.Backend.Filesystem}
iex> ExZarr.Storage.Registry.get(:nonexistent)
{:error, :not_found}Returns
{:ok, module()}- Backend found{:error, :not_found}- Backend not registered
@spec info(backend_id()) :: {:ok, map()} | {:error, :not_found}
Gets information about a storage backend.
Returns backend metadata if the module provides a backend_info/0 callback,
otherwise returns basic information.
Examples
iex> ExZarr.Storage.Registry.info(:filesystem)
{:ok, %{
id: :filesystem,
module: ExZarr.Storage.Backend.Filesystem,
description: "Local filesystem storage"
}}Returns
{:ok, map()}- Backend information{:error, :not_found}- Backend not registered
@spec list() :: [backend_id()]
Lists all registered backend IDs.
Examples
iex> ExZarr.Storage.Registry.list()
[:memory, :filesystem, :zip, :s3, :database]
@spec register( backend_module(), keyword() ) :: :ok | {:error, term()}
Registers a custom storage backend module.
The module must implement the Backend behavior.
Options
:force- Iftrue, overwrites existing backend with same ID (default:false)
Examples
iex> ExZarr.Storage.Registry.register(MyApp.S3Storage)
:ok
iex> ExZarr.Storage.Registry.register(MyBackend, force: true)
:okReturns
:ok- Backend registered successfully{:error, :already_registered}- Backend ID already in use (unlessforce: true){:error, :invalid_backend}- Module doesn't implement Backend behavior
@spec start_link(keyword()) :: GenServer.on_start()
Starts the storage backend registry.
This is typically called automatically by the application supervision tree.
@spec unregister(backend_id()) :: :ok | {:error, term()}
Unregisters a storage backend by ID.
Built-in backends cannot be unregistered.
Examples
iex> ExZarr.Storage.Registry.unregister(:my_backend)
:ok
iex> ExZarr.Storage.Registry.unregister(:filesystem)
{:error, :cannot_unregister_builtin}Returns
:ok- Backend unregistered successfully{:error, :not_found}- Backend not registered{:error, :cannot_unregister_builtin}- Cannot unregister built-in backend