File tree 1 file changed +9
-5
lines changed
1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change @@ -452,11 +452,15 @@ impl Read for File {
452
452
fn size_snapshot ( & self ) -> Option < usize > {
453
453
if let Ok ( meta) = self . metadata ( ) {
454
454
let len = meta. len ( ) ;
455
- let size = len as usize ;
456
- // Don't trust a length of zero. For example, "pseudofiles" on Linux
457
- // like /proc/meminfo report a size of 0.
458
- if size != 0 && size as u64 == len {
459
- return Some ( size) ;
455
+ if let Ok ( position) = self . inner . seek ( SeekFrom :: Current ( 0 ) ) {
456
+ if let Some ( distance) = len. checked_sub ( position) {
457
+ let size = distance as usize ;
458
+ // Don't trust a length of zero. For example, "pseudofiles"
459
+ // on Linux like /proc/meminfo report a size of 0.
460
+ if size != 0 && size as u64 == distance {
461
+ return Some ( size) ;
462
+ }
463
+ }
460
464
}
461
465
}
462
466
None
You can’t perform that action at this time.
0 commit comments