#io-read #data-stream #io-stream #read-stream #peekable #checkpoints #peek

peekbufread

Implements a peekable std::io::Read with support for checkpoints

7 releases

0.2.0 Mar 14, 2024
0.1.6 Jul 30, 2022

#94 in Profiling

Download history 15/week @ 2024-02-19 58/week @ 2024-02-26 101/week @ 2024-03-11 16/week @ 2024-03-18

175 downloads per month

MIT license

11KB
197 lines

peekbufread

Allows to peek data of abitrary std::io::Read and comes with supports for checkpoints. Both features work by buffering parts of the original stream.

This crate is intentionally kept very simple: it only offers the struct PeekRead and nothing on top of it.

Build & test

git clone https://github.com/codefionn/peekbufread.git
cd peekbufread
cargo test
cargo bench

Peek

Allows to peek data without consuming its contents.

Checkpoints

Allows the program to forget that data of a stream was already read.

Checkpoint support is optional, but included by default, disable by

peekbufread = { version = "*", default-features = false }

This makes the performance of the crate faster (this issue is currently under investigation).


lib.rs:

Allows to peek data of abitrary std::io::Read and comes with supports for checkpoints. Both features work by buffering parts of the original stream.

This crate is intentionally kept very simple: it only offers the struct PeekRead and nothing on top of it.

Example

use peekbufread::PeekRead;
use std::io::Read;

let test = b"hello, world";
let mut read = PeekRead::new(test.as_ref());

let mut buf = [0; 12];
read.peek(&mut buf).ok();

let mut buf = [0; 12];
read.read(&mut buf).ok();

No runtime deps