diff --git a/src/local.rs b/src/local.rs index 3404bc8..e67206d 100644 --- a/src/local.rs +++ b/src/local.rs @@ -428,8 +428,8 @@ impl ObjectStore for LocalFileSystem { async fn get_range(&self, location: &Path, range: Range) -> Result { let path = self.path_to_filesystem(location)?; maybe_spawn_blocking(move || { - let (mut file, _) = open_file(&path)?; - read_range(&mut file, &path, range) + let (mut file, metadata) = open_file(&path)?; + read_range(&mut file, metadata.len(), &path, range) }) .await } @@ -439,10 +439,10 @@ impl ObjectStore for LocalFileSystem { let ranges = ranges.to_vec(); maybe_spawn_blocking(move || { // Vectored IO might be faster - let (mut file, _) = open_file(&path)?; + let (mut file, metadata) = open_file(&path)?; ranges .into_iter() - .map(|r| read_range(&mut file, &path, r)) + .map(|r| read_range(&mut file, metadata.len(), &path, r)) .collect() }) .await @@ -899,15 +899,14 @@ pub(crate) fn chunked_stream( .boxed() } -pub(crate) fn read_range(file: &mut File, path: &PathBuf, range: Range) -> Result { - let file_metadata = file.metadata().map_err(|e| Error::Metadata { - source: e.into(), - path: path.to_string_lossy().to_string(), - })?; - +pub(crate) fn read_range( + file: &mut File, + file_len: u64, + path: &PathBuf, + range: Range, +) -> Result { // If none of the range is satisfiable we should error, e.g. if the start offset is beyond the // extents of the file - let file_len = file_metadata.len(); if range.start >= file_len { return Err(Error::InvalidRange { source: InvalidGetRange::StartTooLarge {