7 releases (breaking)
0.6.0 | Feb 14, 2019 |
---|---|
0.5.0 | Feb 14, 2019 |
0.4.0 | Feb 13, 2019 |
0.3.0 | Feb 7, 2019 |
0.1.1 | Feb 5, 2019 |
#1199 in Filesystem
45 downloads per month
Used in 4 crates
(2 directly)
14KB
263 lines
buffered_offset_reader
Rust crate for buffered reading of a file at arbitrary offsets.
Uses std::os::unix::fs::FileExt::read_at()
on unix (aka pread()
)
or std::os::windows::fs::FileExt::seek_read()
on windows to do thread-safe
reads of the underlying file.
Examples
use buffered_offset_reader::{BufOffsetReader, OffsetReadMut};
use std::fs::File;
fn main() -> std::io::Result<()> {
let f = File::open("log.txt")?;
let mut reader = BufOffsetReader::new(f);
let mut tmp = vec![0; 8];
reader.read_at(&mut tmp, 0)?; // read 8 bytes at offset 0
// This read will be fulfilled by the reader's internal buffer,
// so it won't require a system call.
reader.read_at(&mut tmp, 32)?; // read 8 bytes at offset 32
Ok(())
}