Bytes
The byte iterator reads a file one byte at a time. In Rust it yields Result<u8>; in Python it yields single-byte bytes objects
This iterator has no extra options beyond the common ones (state, start, end, skip, limit). It is useful for binary protocols or when you need byte-level control
Basic Usage
Rust
use preader::PReader;
let reader = PReader::default();
let bytes: Vec<u8> = reader.bytes("data.bin")
.build()?
.collect::<preader::Result<_>>()?;
println!("read {} bytes", bytes.len());
Python
from preader import PReader
reader = PReader()
data = b"".join(reader.bytes("data.bin"))
print(f"read {len(data)} bytes")
Reading a Window
You can combine skip and limit to read a specific range of bytes
Rust
// Read 4 bytes starting from the 4th byte (skip first 3)
let window = reader.bytes("data.bin")
.skip(3)
.limit(4)
.build()?
.collect::<preader::Result<Vec<_>>>()?;
Python
from preader import IteratorOptions
options = IteratorOptions(skip=3, limit=4)
window = b"".join(reader.bytes("data.bin", options=options))
For the byte iterator,
skipandlimitcount individual bytes. Theskipvalue is folded into the start offset at build time, so skipped bytes are never read from disk