@@ -1247,9 +1247,39 @@ impl Write for &File {
12471247}
12481248#[ stable( feature = "rust1" , since = "1.0.0" ) ]
12491249impl Seek for & File {
1250+ /// Seek to an offset, in bytes in a file.
1251+ ///
1252+ /// See [`Seek::seek`] docs for more info.
1253+ ///
1254+ /// # Platform-specific behavior
1255+ ///
1256+ /// This function currently corresponds to the `lseek64` function on Unix
1257+ /// and the `SetFilePointerEx` function on Windows. Note that this [may
1258+ /// change in the future][changes].
1259+ ///
1260+ /// [changes]: io#platform-specific-behavior
12501261 fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
12511262 self . inner . seek ( pos)
12521263 }
1264+
1265+ /// Returns the length of this file (in bytes).
1266+ ///
1267+ /// See [`Seek::stream_len`] docs for more info.
1268+ ///
1269+ /// # Platform-specific behavior
1270+ ///
1271+ /// This function currently corresponds to the `statx` function on Linux
1272+ /// (with fallbacks) and the `GetFileSizeEx` function on Windows. Note that
1273+ /// this [may change in the future][changes].
1274+ ///
1275+ /// [changes]: io#platform-specific-behavior
1276+ fn stream_len ( & mut self ) -> io:: Result < u64 > {
1277+ if let Some ( result) = self . inner . size ( ) {
1278+ return result;
1279+ }
1280+ io:: stream_len_default ( self )
1281+ }
1282+
12531283 fn stream_position ( & mut self ) -> io:: Result < u64 > {
12541284 self . inner . tell ( )
12551285 }
@@ -1299,6 +1329,9 @@ impl Seek for File {
12991329 fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
13001330 ( & * self ) . seek ( pos)
13011331 }
1332+ fn stream_len ( & mut self ) -> io:: Result < u64 > {
1333+ ( & * self ) . stream_len ( )
1334+ }
13021335 fn stream_position ( & mut self ) -> io:: Result < u64 > {
13031336 ( & * self ) . stream_position ( )
13041337 }
@@ -1348,6 +1381,9 @@ impl Seek for Arc<File> {
13481381 fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
13491382 ( & * * self ) . seek ( pos)
13501383 }
1384+ fn stream_len ( & mut self ) -> io:: Result < u64 > {
1385+ ( & * * self ) . stream_len ( )
1386+ }
13511387 fn stream_position ( & mut self ) -> io:: Result < u64 > {
13521388 ( & * * self ) . stream_position ( )
13531389 }
0 commit comments