AdamGS commented on code in PR #628:
URL:
https://github.com/apache/arrow-rs-object-store/pull/628#discussion_r2741285950
##########
src/local.rs:
##########
@@ -988,26 +988,79 @@ pub(crate) fn read_range(
// Don't read past end of file
let to_read = range.end.min(file_len) - range.start;
+ let mut buf = Vec::with_capacity(to_read as usize);
- file.seek(SeekFrom::Start(range.start)).map_err(|source| {
- let path = path.into();
- Error::Seek { source, path }
- })?;
+ #[cfg(any(target_family = "unix", target_family = "windows"))]
+ {
+ #[cfg(target_family = "unix")]
+ use std::os::unix::fs::FileExt;
+ #[cfg(target_family = "windows")]
+ use std::os::windows::fs::FileExt;
+
+ // Safety:
+ // Setting the buffer's length to its capacity is safe as it remains
within its allocated memory.
+ // In cases where `read_exact_at` errors, the contents of the buffer
are undefined,
+ // but we discard it without using it.
+ unsafe {
+ buf.set_len(to_read as usize);
+ }
- let mut buf = Vec::with_capacity(to_read as usize);
- let read = file.take(to_read).read_to_end(&mut buf).map_err(|source| {
- let path = path.into();
- Error::UnableToReadBytes { source, path }
- })? as u64;
-
- if read != to_read {
- let error = Error::OutOfRange {
- path: path.into(),
- expected: to_read,
- actual: read,
- };
+ let mut buf_slice = &mut buf[..];
+ let mut offset = range.start;
+
+ while !buf_slice.is_empty() {
Review Comment:
this is roughly the implementation of `read_exact_at`, just allows us to
keep the same errors and track how many bytes we've read for the `OutOfRange`
error branch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]