Random-access byte source.
pread/3 reads at most length bytes starting at offset. A read that
starts at or past the end returns {:ok, ""}. A read that extends past
the end returns the bytes that remain. Implementations return a tagged
error instead of raising.
BAM.Source.File and BAM.Source.Memory are the built-in sources. A
custom source implements the same three callbacks. Offsets are absolute,
so a caller can seek to a BGZF virtual offset without consuming the bytes
in between.
Summary
Callbacks
Releases the source. Closing a closed source returns {:ok, state}.
Reads at most length bytes starting at offset.
Byte length of the source.
Functions
Reads exactly length bytes, or a truncated error.
Types
@type state() :: term()
Opaque handle owned by one source implementation.
Callbacks
@callback close(state()) :: {:ok, state()} | {:error, BAM.Error.t()}
Releases the source. Closing a closed source returns {:ok, state}.
@callback pread(state(), non_neg_integer(), non_neg_integer()) :: {:ok, binary()} | {:error, BAM.Error.t()}
Reads at most length bytes starting at offset.
@callback size(state()) :: {:ok, non_neg_integer()} | {:error, BAM.Error.t()}
Byte length of the source.
Functions
@spec pread_exact(module(), state(), non_neg_integer(), non_neg_integer(), map()) :: {:ok, binary()} | {:error, BAM.Error.t()}
Reads exactly length bytes, or a truncated error.