@@ -823,9 +823,38 @@ impl Write for &File {
823
823
}
824
824
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
825
825
impl Seek for & File {
826
+ /// Seek to an offset, in bytes in a file.
827
+ ///
828
+ /// See [`Seek::seek`] docs for more info.
829
+ ///
830
+ /// # Platform-specific behavior
831
+ ///
832
+ /// This function currently corresponds to the `lseek64` function on Unix
833
+ /// and the `SetFilePointerEx` function on Windows. Note that this [may
834
+ /// change in the future][changes].
835
+ ///
836
+ /// [changes]: io#platform-specific-behavior
826
837
fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
827
838
self . inner . seek ( pos)
828
839
}
840
+
841
+ /// Returns the length of this file (in bytes).
842
+ ///
843
+ /// See [`Seek::stream_len`] docs for more info.
844
+ ///
845
+ /// # Platform-specific behavior
846
+ ///
847
+ /// This function currently corresponds to the `statx` function on Linux
848
+ /// (with fallbacks) and the `GetFileSizeEx` function on Windows. Note that
849
+ /// this [may change in the future][changes].
850
+ ///
851
+ /// [changes]: io#platform-specific-behavior
852
+ fn stream_len ( & mut self ) -> io:: Result < u64 > {
853
+ if let Some ( result) = self . inner . size ( ) {
854
+ return result;
855
+ }
856
+ io:: stream_len_default ( self )
857
+ }
829
858
}
830
859
831
860
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -872,6 +901,9 @@ impl Seek for File {
872
901
fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
873
902
( & * self ) . seek ( pos)
874
903
}
904
+ fn stream_len ( & mut self ) -> io:: Result < u64 > {
905
+ ( & * self ) . stream_len ( )
906
+ }
875
907
}
876
908
877
909
#[ stable( feature = "io_traits_arc" , since = "1.73.0" ) ]
@@ -918,6 +950,9 @@ impl Seek for Arc<File> {
918
950
fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
919
951
( & * * self ) . seek ( pos)
920
952
}
953
+ fn stream_len ( & mut self ) -> io:: Result < u64 > {
954
+ ( & * self ) . stream_len ( )
955
+ }
921
956
}
922
957
923
958
impl OpenOptions {
0 commit comments