ExStorageService.BlobStore.Source (ex_storage_service v0.6.2)

Copy Markdown View Source

A servable blob source.

File sources retain an explicit offset and length so callers can use send_file for loose, legacy, packed, and ranged reads. Stateful stream producers thread adapter state such as Plug.Conn without an auxiliary process or object-sized buffering.

Summary

Functions

Returns the exact number of bytes exposed by a source.

Reduces a stream source while preserving caller state between chunks.

Adapts a source to a bounded request-body enumerable.

Types

producer(acc)

@type producer(acc) :: (acc, reducer(acc) -> {:ok, acc} | {:error, term(), acc})

reduce_result(acc)

@type reduce_result(acc) :: {:cont, acc} | {:halt, term(), acc}

reducer(acc)

@type reducer(acc) :: (binary(), acc -> reduce_result(acc))

t()

@type t() ::
  {:file, String.t(), non_neg_integer(), non_neg_integer()}
  | {:stream, Enumerable.t() | function() | {:stateful, function()},
     non_neg_integer()}

Functions

content_length(arg)

@spec content_length(t()) :: non_neg_integer()

Returns the exact number of bytes exposed by a source.

file(path, offset, length)

@spec file(String.t(), non_neg_integer(), non_neg_integer()) :: t()

reduce(arg, initial, reducer)

@spec reduce(t(), acc, reducer(acc)) :: {:ok, acc} | {:error, term(), acc}
when acc: term()

Reduces a stream source while preserving caller state between chunks.

{:halt, reason, state} cancels a callback-backed upstream immediately and returns the final caller state alongside the reason.

request_body(source)

@spec request_body(t()) :: Enumerable.t()

Adapts a source to a bounded request-body enumerable.

The adapter is intended for HTTP/1 clients that consume request enumerables without suspension. Each upstream chunk is passed directly to the HTTP reducer; no object-sized binary is assembled.

stateful_stream(producer, content_length)

@spec stateful_stream(producer(acc), non_neg_integer()) :: t() when acc: term()

stream(enumerable_or_callback, content_length)

@spec stream(Enumerable.t() | function() | {:stateful, function()}, non_neg_integer()) ::
  t()