@@ -1226,9 +1226,38 @@ impl Write for &File {
1226
1226
}
1227
1227
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1228
1228
impl Seek for & File {
1229
+ /// Seek to an offset, in bytes in a file.
1230
+ ///
1231
+ /// See [`Seek::seek`] docs for more info.
1232
+ ///
1233
+ /// # Platform-specific behavior
1234
+ ///
1235
+ /// This function currently corresponds to the `lseek64` function on Unix
1236
+ /// and the `SetFilePointerEx` function on Windows. Note that this [may
1237
+ /// change in the future][changes].
1238
+ ///
1239
+ /// [changes]: io#platform-specific-behavior
1229
1240
fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
1230
1241
self . inner . seek ( pos)
1231
1242
}
1243
+
1244
+ /// Returns the length of this file (in bytes).
1245
+ ///
1246
+ /// See [`Seek::stream_len`] docs for more info.
1247
+ ///
1248
+ /// # Platform-specific behavior
1249
+ ///
1250
+ /// This function currently corresponds to the `statx` function on Linux
1251
+ /// (with fallbacks) and the `GetFileSizeEx` function on Windows. Note that
1252
+ /// this [may change in the future][changes].
1253
+ ///
1254
+ /// [changes]: io#platform-specific-behavior
1255
+ fn stream_len ( & mut self ) -> io:: Result < u64 > {
1256
+ if let Some ( result) = self . inner . size ( ) {
1257
+ return result;
1258
+ }
1259
+ io:: stream_len_default ( self )
1260
+ }
1232
1261
}
1233
1262
1234
1263
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -1275,6 +1304,9 @@ impl Seek for File {
1275
1304
fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
1276
1305
( & * self ) . seek ( pos)
1277
1306
}
1307
+ fn stream_len ( & mut self ) -> io:: Result < u64 > {
1308
+ ( & * self ) . stream_len ( )
1309
+ }
1278
1310
}
1279
1311
1280
1312
#[ stable( feature = "io_traits_arc" , since = "1.73.0" ) ]
@@ -1321,6 +1353,9 @@ impl Seek for Arc<File> {
1321
1353
fn seek ( & mut self , pos : SeekFrom ) -> io:: Result < u64 > {
1322
1354
( & * * self ) . seek ( pos)
1323
1355
}
1356
+ fn stream_len ( & mut self ) -> io:: Result < u64 > {
1357
+ ( & * * self ) . stream_len ( )
1358
+ }
1324
1359
}
1325
1360
1326
1361
impl OpenOptions {
0 commit comments