Data source abstraction for the streaming DICOM parser.
Provides a uniform interface over binary buffers and file I/O with read-ahead buffering. The source supports three operations:
ensure/2-- guarantee N bytes are available in the bufferconsume/2-- consume N bytes from the bufferpeek/2-- read N bytes without consuming
Source Types
- Binary: wraps an in-memory binary, no I/O
- File: reads from a file handle with configurable read-ahead buffering
Stability
This module may change. It is an internal implementation detail of the streaming parser and should not be relied on directly by consumers.
Summary
Functions
Returns the number of bytes currently available in the buffer.
Returns the total bytes consumed from this source.
Consumes n bytes from the buffer, returning them and the updated source.
Consumes bytes until marker is found, excluding the marker from the returned data.
Consumes bytes until marker is found, excluding the marker from the returned data.
Ensures at least n bytes are available in the buffer.
Returns true if the source is exhausted (EOF and empty buffer).
Creates a source from an in-memory binary.
Creates a source from an open file handle (opened in :raw, :binary, :read mode).
Peeks at the next n bytes without consuming them.
Types
@type t() :: %Dicom.P10.Stream.Source{ buffer: binary(), io: :eof | io_device() | nil, offset: non_neg_integer(), read_ahead: pos_integer() }
Functions
@spec available(t()) :: non_neg_integer()
Returns the number of bytes currently available in the buffer.
@spec bytes_consumed(t()) :: non_neg_integer()
Returns the total bytes consumed from this source.
@spec consume(t(), non_neg_integer()) :: {:ok, binary(), t()}
Consumes n bytes from the buffer, returning them and the updated source.
Consumes bytes until marker is found, excluding the marker from the returned data.
If the marker is not found before EOF, consumes and returns the remaining buffer.
Consumes bytes until marker is found, excluding the marker from the returned data.
Returns {:error, :unexpected_end} if EOF is reached before the marker appears.
@spec ensure(t(), non_neg_integer()) :: {:ok, t()} | {:error, :unexpected_end}
Ensures at least n bytes are available in the buffer.
Returns {:ok, source} if the buffer has >= n bytes after filling,
or {:error, :unexpected_end} if the source is exhausted.
Returns true if the source is exhausted (EOF and empty buffer).
Creates a source from an in-memory binary.
Creates a source from an open file handle (opened in :raw, :binary, :read mode).
Options
:read_ahead-- preferred read-ahead buffer size in bytes (default: 65536)
@spec peek(t(), non_neg_integer()) :: {:ok, binary()} | {:error, :unexpected_end}
Peeks at the next n bytes without consuming them.