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
@type reduce_result(acc) :: {:cont, acc} | {:halt, term(), acc}
@type reducer(acc) :: (binary(), acc -> reduce_result(acc))
@type t() :: {:file, String.t(), non_neg_integer(), non_neg_integer()} | {:stream, Enumerable.t() | function() | {:stateful, function()}, non_neg_integer()}
Functions
@spec content_length(t()) :: non_neg_integer()
Returns the exact number of bytes exposed by a source.
@spec file(String.t(), non_neg_integer(), non_neg_integer()) :: t()
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.
@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.
@spec stateful_stream(producer(acc), non_neg_integer()) :: t() when acc: term()
@spec stream(Enumerable.t() | function() | {:stateful, function()}, non_neg_integer()) :: t()