From 0ef34c911993f377ba77bc10e21d85a76572d301 Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Thu, 21 Mar 2024 14:36:20 +0800 Subject: [PATCH] feat: Add read at support for file (#130) Signed-off-by: Xuanwo --- src/file.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/file.rs b/src/file.rs index 124ff73..cfab1e6 100644 --- a/src/file.rs +++ b/src/file.rs @@ -81,6 +81,24 @@ impl File { Ok(n) } + + pub fn read_at(&self, buf: &mut [u8], offset: u64) -> Result { + 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 {