pub struct StreamReader<'a> { /* private fields */ }Expand description
Scans a buffer for commits and exposes the committed region, block by block, and its records. Zero-copy: accessors return slices into the original buffer.
Implementations§
Source§impl<'a> StreamReader<'a>
impl<'a> StreamReader<'a>
Sourcepub fn continuing(buf: &'a [u8]) -> Self
pub fn continuing(buf: &'a [u8]) -> Self
A reader that skips damaged blocks and reads on.
pub fn buf(&self) -> &'a [u8] ⓘ
Sourcepub fn committed_end(&self) -> usize
pub fn committed_end(&self) -> usize
Offset just past the last ETB and its payload.
Sourcepub fn torn(&self) -> bool
pub fn torn(&self) -> bool
Whether data trails the last commit (layout, notes and EOT alone do not count).
Sourcepub fn torn_regions(&self) -> &[(usize, usize)]
pub fn torn_regions(&self) -> &[(usize, usize)]
[start, end) of every region torn by a SYN inside the stream: the
uncommitted bytes between a commit (or the start) and the SYN that
began the next document. They belong to no block and deliver
nothing. Layout alone before a SYN is not a tear. The torn tail
after the last commit is StreamReader::torn, not listed here.
Sourcepub fn continue_past_damage(&self) -> bool
pub fn continue_past_damage(&self) -> bool
Whether the reader goes on past a damaged block.
pub fn block_count(&self) -> usize
Sourcepub fn block(&self, i: usize) -> &'a [u8] ⓘ
pub fn block(&self, i: usize) -> &'a [u8] ⓘ
Committed block i: the bytes from the previous commit to this
block’s ETB (marker and payload excluded).
Sourcepub fn block_ranges(&self) -> &[(usize, usize)]
pub fn block_ranges(&self) -> &[(usize, usize)]
[start, end) of every committed block.
pub fn blocks(&self) -> impl Iterator<Item = &'a [u8]> + '_
Sourcepub fn block_end(&self, i: usize) -> usize
pub fn block_end(&self, i: usize) -> usize
Offset after a block’s ETB and payload: the start of the next block.
pub fn is_damaged(&self, i: usize) -> bool
Sourcepub fn undamaged(&self) -> Cow<'a, [u8]>
pub fn undamaged(&self) -> Cow<'a, [u8]>
The committed region with damaged blocks removed: borrowed when no block is damaged, otherwise the sound blocks concatenated.
Sourcepub fn container(&self) -> Result<&Container<'a>>
pub fn container(&self) -> Result<&Container<'a>>
The committed region as documents, damaged blocks left out. Fails
with Error::DamagedBlock when a block is damaged, unless the
reader continues past damage.
Sourcepub fn each_record<F: FnMut(&Record<'a>)>(&self, f: F) -> Result<()>
pub fn each_record<F: FnMut(&Record<'a>)>(&self, f: F) -> Result<()>
Every committed record in order, up to the first damaged block; then
Error::DamagedBlock, unless continuing, in which case every
record of every sound block.