[][src]Crate seek_bufread

The BufReader is a drop-in replacement for std::io::BufReader with seeking support.

If .seek(SeekFrom::Current(n)) is called and n is in range of the internal buffer the underlying reader is not invoked. This has the side effect that you can no longer access the underlying buffer directly after being consumed by BufReader, because its position could be out of sync.

Examples

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]);

Structs

BufReader

The BufReader struct adds buffering to any reader.