etseidl commented on code in PR #6751:
URL: https://github.com/apache/arrow-rs/pull/6751#discussion_r1850747732


##########
object_store/src/local.rs:
##########
@@ -897,23 +897,26 @@ pub(crate) fn chunked_stream(
 
 pub(crate) fn read_range(file: &mut File, path: &PathBuf, range: Range<usize>) 
-> Result<Bytes> {
     let to_read = range.end - range.start;
-    file.seek(SeekFrom::Start(range.start as u64))
+    let seek_idx = file
+        .seek(SeekFrom::Start(range.start as u64))
         .context(SeekSnafu { path })?;
 
-    let mut buf = Vec::with_capacity(to_read);
-    let read = file
-        .take(to_read as u64)
-        .read_to_end(&mut buf)
-        .context(UnableToReadBytesSnafu { path })?;
-
     ensure!(
-        read == to_read,
+        seek_idx == range.start as u64,

Review Comment:
   It appears this will always be true, even if seeking beyond EOF.



##########
object_store/src/local.rs:
##########
@@ -897,23 +897,26 @@ pub(crate) fn chunked_stream(
 
 pub(crate) fn read_range(file: &mut File, path: &PathBuf, range: Range<usize>) 
-> Result<Bytes> {
     let to_read = range.end - range.start;
-    file.seek(SeekFrom::Start(range.start as u64))
+    let seek_idx = file
+        .seek(SeekFrom::Start(range.start as u64))
         .context(SeekSnafu { path })?;
 
-    let mut buf = Vec::with_capacity(to_read);
-    let read = file
-        .take(to_read as u64)
-        .read_to_end(&mut buf)
-        .context(UnableToReadBytesSnafu { path })?;
-
     ensure!(
-        read == to_read,
+        seek_idx == range.start as u64,
         OutOfRangeSnafu {
             path,
-            expected: to_read,
-            actual: read
+            expected: range.start,
+            actual: seek_idx as usize
         }
     );
+
+    let mut buf = Vec::with_capacity(to_read);
+    file.take(to_read as u64)
+        .read_to_end(&mut buf)
+        .context(UnableToReadBytesSnafu { path })?;

Review Comment:
   Likewise, this read will simply return 0 when reading beyond EOF.



-- 
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]

Reply via email to