Skip to content

Instantly share code, notes, and snippets.

@ugovaretto
Created May 19, 2022 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ugovaretto/219908de8ab899d27a77fd08668758cb to your computer and use it in GitHub Desktop.
Save ugovaretto/219908de8ab899d27a77fd08668758cb to your computer and use it in GitHub Desktop.
read_at with Rust
#[cfg(any(windows))]
fn load_exact_bytes_at(buffer: &mut Vec<u8>, file: &File, offset: u64) {
use std::os::windows::fs::FileExt;
let mut data_read = 0;
while data_read < buffer.len() {
data_read += file.seek_read(buffer, offset).unwrap();
}
}
#[cfg(any(unix))]
fn load_exact_bytes_at(buffer: &mut Vec<u8>, file: &File, offset: u64) {
use std::os::unix::fs::FileExt;
let mut data_read = 0;
while data_read < buffer.len() {
data_read += file.read_at(buffer, offset).unwrap();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment