Created
May 19, 2022 01:11
-
-
Save ugovaretto/219908de8ab899d27a77fd08668758cb to your computer and use it in GitHub Desktop.
read_at with Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[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