Skip to content

Commit

Permalink
feat: Add read at support for file (#130)
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo authored Mar 21, 2024
1 parent 7ca47d6 commit 0ef34c9
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ impl File {

Ok(n)
}

pub fn read_at(&self, buf: &mut [u8], offset: u64) -> Result<usize> {
let n = unsafe {
hdfsPread(
self.fs,
self.f,
offset as i64,
buf.as_ptr() as *mut c_void,
buf.len().min(FILE_LIMIT) as i32,
)
};

if n == -1 {
return Err(Error::last_os_error());
}

Ok(n as usize)
}
}

impl Read for File {
Expand Down

0 comments on commit 0ef34c9

Please sign in to comment.