#bufread #buffer #io #reader #seek #replace

seek_bufread

A drop-in replacement for std::io::BufReader with seeking support

5 stable releases

Uses old Rust 2015

1.2.2 Dec 6, 2018
1.2.0 Oct 22, 2016
1.1.1 Oct 22, 2016
1.0.2 Oct 21, 2016

#6 in #seek

Download history 91/week @ 2024-07-19 84/week @ 2024-07-26 70/week @ 2024-08-02 122/week @ 2024-08-09 75/week @ 2024-08-16 103/week @ 2024-08-23 138/week @ 2024-08-30 67/week @ 2024-09-06 61/week @ 2024-09-13 92/week @ 2024-09-20 69/week @ 2024-09-27 35/week @ 2024-10-04 45/week @ 2024-10-11 43/week @ 2024-10-18 42/week @ 2024-10-25 68/week @ 2024-11-01

199 downloads per month
Used in 10 crates (8 directly)

Apache-2.0

21KB
323 lines

seek_bufread

Build Status Coverage Status Crates.io

A drop-in replacement for std::io::BufReader with seeking support.

Full Documentation

Quick Example

use std::io::{self, Cursor, Read, Seek, SeekFrom};
use seek_bufread::BufReader;

let inner = Cursor::new([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
let mut reader = BufReader::new(inner);

reader.seek(SeekFrom::Current(4)).unwrap();
let mut buf = [0; 8];

// read bytes from internal buffer
reader.read(&mut buf).unwrap();
assert_eq!(buf, [4, 5, 6, 7, 8, 9, 10, 11]);

Usage

Put this in your Cargo.toml:

[dependencies]
seek_bufread = "~1.2"

And this in your crate root:

extern crate seek_bufread;

Benchmarks

Tests with the suffix _std are using the standard std::io::BufRead implementation. The Overall performance without seek operations is quite similar between both. With seek operations seek_bufread::BufRead is significantly faster.

test tests::read_10mb_default_from_cursor        ... bench:   6,044,915 ns/iter (+/- 275,518)
test tests::read_10mb_default_from_cursor_std    ... bench:   6,038,466 ns/iter (+/- 227,145)
test tests::read_10mb_default_from_file          ... bench:   4,213,179 ns/iter (+/- 116,043)
test tests::read_10mb_default_from_file_std      ... bench:   4,224,658 ns/iter (+/- 132,629)
test tests::read_10mb_fullbuf_from_file          ... bench:   7,280,470 ns/iter (+/- 209,827)
test tests::read_10mb_fullbuf_from_file_std      ... bench:   7,448,666 ns/iter (+/- 2,720,199)
test tests::read_10mb_halfbuf_from_file          ... bench:   5,962,017 ns/iter (+/- 415,952)
test tests::read_10mb_halfbuf_from_file_std      ... bench:   5,904,902 ns/iter (+/- 240,471)
test tests::read_seek_10mb_default_from_file     ... bench:       6,621 ns/iter (+/- 145)
test tests::read_seek_10mb_default_from_file_std ... bench:      59,651 ns/iter (+/- 1,993)
test tests::read_seek_10mb_halfbuf_from_file     ... bench:   1,168,511 ns/iter (+/- 63,956)
test tests::read_seek_10mb_halfbuf_from_file_std ... bench:  62,872,335 ns/iter (+/- 5,344,766)

License

Apache-2.0

No runtime deps