#byte-slice #byte #iterator #chunk #byte-reader

read-byte-slice

An iterator over chunks of bytes as slices from an underlying reader

3 releases

Uses old Rust 2015

0.1.2 Dec 8, 2017
0.1.1 Sep 5, 2017
0.1.0 Sep 1, 2017

#2459 in Algorithms

Download history 6/week @ 2024-12-04 51/week @ 2024-12-11 13/week @ 2024-12-18 10/week @ 2025-01-08 17/week @ 2025-01-15 13/week @ 2025-01-22 3/week @ 2025-01-29 27/week @ 2025-02-05 32/week @ 2025-02-12 3/week @ 2025-02-19 23/week @ 2025-02-26

86 downloads per month
Used in 2 crates

MIT/Apache

9KB
112 lines

Build Status crates.io

This crate implements a type ByteSliceIter that 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.)

Example

extern crate read_byte_slice;

use read_byte_slice::{ByteSliceIter, FallibleStreamingIterator};
use std::io;

fn work() -> io::Result<()> {
  let bytes = b"0123456789abcdef0123456789abcdef";
  // Iterate over the bytes in 8-byte chunks.
  let mut iter = ByteSliceIter::new(&bytes[..], 8);
  while let Some(chunk) = iter.next()? {
    println!("{:?}", chunk);
  }
  Ok(())
}

fn main() {
  work().unwrap();
}

License

read-byte-slice is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

Dependencies

~23KB