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

Types

A blob being read in pieces.

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

config()

@type config() :: keyword()

key()

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

reader()

@type reader() :: %{
  read: (offset :: non_neg_integer() ->
           {:ok, binary()} | :eof | {:error, term()}),
  close: (-> :ok)
}

A blob being read in pieces.

Callbacks

delete(config, key)

@callback delete(config(), key()) :: :ok | {:error, term()}

get(config, key)

@callback get(config(), key()) :: {:ok, binary()} | {:error, :not_found | term()}

get_range(config, key, first, last)

(optional)
@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.

open(config, key)

@callback open(config(), key()) :: {:ok, reader()} | {:error, :not_found | term()}

put(config, key, size, data)

@callback put(config(), key(), size :: non_neg_integer(), data :: Enumerable.t()) ::
  :ok | {:error, term()}