Crate read_byte_slice

Source
Expand description

ByteSliceIter reads bytes from a reader and allows iterating over them as slices with a maximum length, similar to the chunks method on slices.

It is implemented as a FallibleStreamingIterator so that it can reuse its buffer and not allocate for each chunk. (That trait is re-exported here for convenience.)

§Examples

use read_byte_slice::{ByteSliceIter, FallibleStreamingIterator};
use std::fs::File;
let f = File::open("src/lib.rs")?;
// Iterate over the file's contents in 8-byte chunks.
let mut iter = ByteSliceIter::new(f, 8);
while let Some(chunk) = iter.next()? {
    println!("{:?}", chunk);
}

Structs§

  • An iterator over byte slices from a Read that reuses the same buffer instead of allocating.

Traits§