Skip to main content

Module stream

Module stream 

Source
Expand description

std::io::Read + std::io::Seek adapter over any BlockRead.

Every consumer that wants to stream a positioned-read device top-to-bottom (hashing, copying, burning, feeding into a parser that expects Read) otherwise reinvents the same cursor wrapper: track the current offset, call read_at, advance, clamp at size_bytes, signal EOF. BlockReadStreamer is that wrapper, once.

Generic over T: BlockRead so the parent can be owned, Arc-held, or borrowed:

use fs_core::{BlockReadStreamer, FileDevice};
use std::io::Read;

let dev = FileDevice::open("disk.img")?;
let mut stream = BlockReadStreamer::new(dev);
let mut hasher = sha2::Sha256::new();
std::io::copy(&mut stream, &mut hasher)?;

Short-read semantics match std::io::Read: a read past size_bytes() is clamped, not an error; a read at or past the end returns Ok(0).

Structs§

BlockReadStreamer
Sequential Read + Seek adapter over any BlockRead.