wasm_storage_ns behaviour (wasm_storage v0.1.0)
View SourceNamed storage: a root that devices are opened in by relative path.
A random-access device (wasm_storage) is enough for an engine that keeps
one file, like redb. An engine that creates, deletes and renames files, like
SQLite with its journal, also needs a namespace. A root is a capability: it
grants a directory (or any other provider's notion of one) and nothing above
it.
{ok, Root} = wasm_storage_ns:root({wasm_storage_dir, "/var/db/app"}, #{}),
{ok, H} = wasm_storage_ns:open(Root, <<"main.db">>, #{create => true}),
ok = wasm_storage_ns:delete(Root, <<"main.db-journal">>).Paths are relative, /-separated binaries. This module refuses, before any
provider sees them: an empty path, an absolute path, an empty, . or ..
component, a backslash and a NUL byte. Providers refuse symbolic links.
Summary
Functions
Remove the entry at Path.
The identity of the entry at Path, for wasm_storage_owner.
What the provider says about the root.
Open the device at Path. Opts are those of the provider's device.
Rename From to To, replacing To. Atomic where the provider says so.
root(Spec, #{}).
Open a root. Spec is {Provider, Arg}.
What is at Path, without following a symbolic link.
Make the entries of a directory durable: creations, deletions and renames in
it. <<>> is the root. A provider that cannot do it returns
{error, enotsup}; it never returns ok without doing it.
The components of a valid relative path, or {error, einval}.
Types
-opaque root()
-type stat() :: #{type := regular | directory | symlink | other, size := non_neg_integer(), identity := term()}.
Callbacks
-callback delete(State :: term(), [binary()]) -> ok | {error, wasm_storage:reason()}.
-callback open(State :: term(), [binary()], Opts :: map()) -> {ok, wasm_storage:handle()} | {error, wasm_storage:reason()}.
-callback rename(State :: term(), [binary()], [binary()]) -> ok | {error, wasm_storage:reason()}.
-callback root(Arg :: term(), Opts :: map()) -> {ok, term()} | {error, wasm_storage:reason()}.
-callback stat(State :: term(), [binary()]) -> {ok, stat()} | {error, wasm_storage:reason()}.
-callback sync_directory(State :: term(), [binary()]) -> ok | {error, wasm_storage:reason()}.
Functions
-spec delete(root(), binary()) -> ok | {error, wasm_storage:reason()}.
Remove the entry at Path.
-spec identity(root(), binary()) -> {ok, term()} | {error, wasm_storage:reason()}.
The identity of the entry at Path, for wasm_storage_owner.
What the provider says about the root.
-spec open(root(), binary(), map()) -> {ok, wasm_storage:handle()} | {error, wasm_storage:reason()}.
Open the device at Path. Opts are those of the provider's device.
-spec rename(root(), binary(), binary()) -> ok | {error, wasm_storage:reason()}.
Rename From to To, replacing To. Atomic where the provider says so.
root(Spec, #{}).
-spec root({module(), term()}, map()) -> {ok, root()} | {error, wasm_storage:reason()}.
Open a root. Spec is {Provider, Arg}.
-spec stat(root(), binary()) -> {ok, stat()} | {error, wasm_storage:reason()}.
What is at Path, without following a symbolic link.
-spec sync_directory(root(), binary()) -> ok | {error, wasm_storage:reason()}.
Make the entries of a directory durable: creations, deletions and renames in
it. <<>> is the root. A provider that cannot do it returns
{error, enotsup}; it never returns ok without doing it.
The components of a valid relative path, or {error, einval}.