Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,8 @@ impl ObjectStore for LocalFileSystem {
async fn get_range(&self, location: &Path, range: Range<u64>) -> Result<Bytes> {
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
}
Expand All @@ -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
Expand Down Expand Up @@ -899,15 +899,14 @@ pub(crate) fn chunked_stream(
.boxed()
}

pub(crate) fn read_range(file: &mut File, path: &PathBuf, range: Range<u64>) -> Result<Bytes> {
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<u64>,
) -> Result<Bytes> {
// 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 {
Expand Down