@@ -899,9 +899,38 @@ impl Write for &File {
899
899
}
900
900
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
901
901
impl Seek for & File {
902
+ /// Seek to an offset, in bytes in a file.
903
+ ///
904
+ /// See [`Seek::seek`] docs for more info.
905
+ ///
906
+ /// # Platform-specific behavior
907
+ ///
908
+ /// This function currently corresponds to the `lseek64` function on Unix
909
+ /// and the `SetFilePointerEx` function on Windows. Note that this [may
910
+ /// change in the future][changes].
911
+ ///
912
+ /// [changes]: io#platform-specific-behavior
902
913
fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
903
914
self . inner . seek ( pos)
904
915
}
916
+
917
+ /// Returns the length of this file (in bytes).
918
+ ///
919
+ /// See [`Seek::stream_len`] docs for more info.
920
+ ///
921
+ /// # Platform-specific behavior
922
+ ///
923
+ /// This function currently corresponds to the `statx` function on Linux
924
+ /// (with fallbacks) and the `GetFileSizeEx` function on Windows. Note that
925
+ /// this [may change in the future][changes].
926
+ ///
927
+ /// [changes]: io#platform-specific-behavior
928
+ fn stream_len ( & mut self ) -> io:: Result < u64 > {
929
+ if let Some ( result) = self . inner . size ( ) {
930
+ return result;
931
+ }
932
+ io:: stream_len_default ( self )
933
+ }
905
934
}
906
935
907
936
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -948,6 +977,9 @@ impl Seek for File {
948
977
fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
949
978
( & * self ) . seek ( pos)
950
979
}
980
+ fn stream_len ( & mut self ) -> io:: Result < u64 > {
981
+ ( & * self ) . stream_len ( )
982
+ }
951
983
}
952
984
953
985
#[ stable( feature = "io_traits_arc" , since = "1.73.0" ) ]
@@ -994,6 +1026,9 @@ impl Seek for Arc<File> {
994
1026
fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
995
1027
( & * * self ) . seek ( pos)
996
1028
}
1029
+ fn stream_len ( & mut self ) -> io:: Result < u64 > {
1030
+ ( & * * self ) . stream_len ( )
1031
+ }
997
1032
}
998
1033
999
1034
impl OpenOptions {
0 commit comments