@@ -428,8 +428,8 @@ impl ObjectStore for LocalFileSystem {
428428 async fn get_range ( & self , location : & Path , range : Range < u64 > ) -> Result < Bytes > {
429429 let path = self . path_to_filesystem ( location) ?;
430430 maybe_spawn_blocking ( move || {
431- let ( mut file, _ ) = open_file ( & path) ?;
432- read_range ( & mut file, & path, range)
431+ let ( mut file, metadata ) = open_file ( & path) ?;
432+ read_range ( & mut file, metadata . len ( ) , & path, range)
433433 } )
434434 . await
435435 }
@@ -439,10 +439,10 @@ impl ObjectStore for LocalFileSystem {
439439 let ranges = ranges. to_vec ( ) ;
440440 maybe_spawn_blocking ( move || {
441441 // Vectored IO might be faster
442- let ( mut file, _ ) = open_file ( & path) ?;
442+ let ( mut file, metadata ) = open_file ( & path) ?;
443443 ranges
444444 . into_iter ( )
445- . map ( |r| read_range ( & mut file, & path, r) )
445+ . map ( |r| read_range ( & mut file, metadata . len ( ) , & path, r) )
446446 . collect ( )
447447 } )
448448 . await
@@ -899,15 +899,14 @@ pub(crate) fn chunked_stream(
899899 . boxed ( )
900900}
901901
902- pub ( crate ) fn read_range ( file : & mut File , path : & PathBuf , range : Range < u64 > ) -> Result < Bytes > {
903- let file_metadata = file. metadata ( ) . map_err ( |e| Error :: Metadata {
904- source : e . into ( ) ,
905- path : path . to_string_lossy ( ) . to_string ( ) ,
906- } ) ? ;
907-
902+ pub ( crate ) fn read_range (
903+ file : & mut File ,
904+ file_len : u64 ,
905+ path : & PathBuf ,
906+ range : Range < u64 > ,
907+ ) -> Result < Bytes > {
908908 // If none of the range is satisfiable we should error, e.g. if the start offset is beyond the
909909 // extents of the file
910- let file_len = file_metadata. len ( ) ;
911910 if range. start >= file_len {
912911 return Err ( Error :: InvalidRange {
913912 source : InvalidGetRange :: StartTooLarge {
0 commit comments