Karta. Storage. BlobStore behaviour
(Karta v1.0.0)
Where Karta.Storage keeps encrypted message bodies. A blob store only
ever sees ciphertext.
Implementations: Karta.Storage.BlobStore.S3 (production, any
S3-compatible service) and Karta.Storage.BlobStore.Local (a directory,
for tests and single-node development). Keys are validated by
Karta.Storage before they reach a store: lower-case letters, digits,
/ and - only.
put/4 receives the data as a stream of iodata of exactly size bytes
and must store all of it or nothing: a reader never sees a partial blob.
delete/2 of a missing key succeeds, so deletes can be repeated safely.
open/2 reads a blob in pieces, so that a body never has to be held
whole. read gives the bytes from an offset (fewer than the store's own
piece size at the end, :eof past it); close releases what the store
holds. A store that cannot read in pieces still implements it: it returns
the whole object as one piece.
Summary
Callbacks
Optional: bytes first to last (both included) of the object; fewer
when it ends first, none when it ends before first. Karta.Storage
reads the whole object and cuts it when a store has no get_range/4.
Types
@type config() :: keyword()
@type key() :: String.t()
@type reader() :: %{ read: (offset :: non_neg_integer() -> {:ok, binary()} | :eof | {:error, term()}), close: (-> :ok) }
A blob being read in pieces.
Callbacks
@callback get_range( config(), key(), first :: non_neg_integer(), last :: non_neg_integer() ) :: {:ok, binary()} | {:error, :not_found | term()}
Optional: bytes first to last (both included) of the object; fewer
when it ends first, none when it ends before first. Karta.Storage
reads the whole object and cuts it when a store has no get_range/4.
@callback put(config(), key(), size :: non_neg_integer(), data :: Enumerable.t()) :: :ok | {:error, term()}