BAM.Source behaviour (BAM v0.1.0)

Copy Markdown View Source

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

Types

Opaque handle owned by one source implementation.

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

state()

@type state() :: term()

Opaque handle owned by one source implementation.

Callbacks

close(state)

@callback close(state()) :: {:ok, state()} | {:error, BAM.Error.t()}

Releases the source. Closing a closed source returns {:ok, state}.

pread(state, non_neg_integer, non_neg_integer)

@callback pread(state(), non_neg_integer(), non_neg_integer()) ::
  {:ok, binary()} | {:error, BAM.Error.t()}

Reads at most length bytes starting at offset.

size(state)

@callback size(state()) :: {:ok, non_neg_integer()} | {:error, BAM.Error.t()}

Byte length of the source.

Functions

pread_exact(module, state, offset, length, context)

@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.