Crates.io | buffered_offset_reader |
lib.rs | buffered_offset_reader |
version | 0.6.0 |
source | src |
created_at | 2019-02-05 06:52:15.766523 |
updated_at | 2019-02-14 04:44:24.613208 |
description | Buffered file read_at (pread) |
homepage | |
repository | https://github.com/sbillig/buffered_offset_reader |
max_upload_size | |
id | 112861 |
size | 26,986 |
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.
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(())
}