diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index c550378e7d6b7..1c63280fb0ca6 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -795,6 +795,11 @@ impl Seek for File { fn seek(&mut self, pos: SeekFrom) -> io::Result { self.inner.seek(pos) } + + fn stream_len(&mut self) -> io::Result { + let file_attr = self.inner.file_attr()?; + Ok(file_attr.size()) + } } #[stable(feature = "rust1", since = "1.0.0")] impl Read for &File { @@ -851,6 +856,10 @@ impl Seek for &File { fn seek(&mut self, pos: SeekFrom) -> io::Result { self.inner.seek(pos) } + fn stream_len(&mut self) -> io::Result { + let file_attr = self.inner.file_attr()?; + Ok(file_attr.size()) + } } impl OpenOptions { diff --git a/library/std/src/io/buffered/bufreader.rs b/library/std/src/io/buffered/bufreader.rs index 4f339a18a480e..0b64d4ab4434b 100644 --- a/library/std/src/io/buffered/bufreader.rs +++ b/library/std/src/io/buffered/bufreader.rs @@ -489,6 +489,10 @@ impl Seek for BufReader { ) }) } + + fn stream_len(&mut self) -> io::Result { + self.inner.stream_len() + } } impl SizeHint for BufReader { diff --git a/library/std/src/io/buffered/bufwriter.rs b/library/std/src/io/buffered/bufwriter.rs index 6acb937e78479..d7697db878c9b 100644 --- a/library/std/src/io/buffered/bufwriter.rs +++ b/library/std/src/io/buffered/bufwriter.rs @@ -661,6 +661,10 @@ impl Seek for BufWriter { self.flush_buf()?; self.get_mut().seek(pos) } + + fn stream_len(&mut self) -> io::Result { + self.inner.stream_len() + } } #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/std/src/io/impls.rs b/library/std/src/io/impls.rs index e5048dcc8acd9..bcbf978432b3b 100644 --- a/library/std/src/io/impls.rs +++ b/library/std/src/io/impls.rs @@ -93,6 +93,11 @@ impl Seek for &mut S { fn stream_position(&mut self) -> io::Result { (**self).stream_position() } + + #[inline] + fn stream_len(&mut self) -> io::Result { + (**self).stream_len() + } } #[stable(feature = "rust1", since = "1.0.0")] impl BufRead for &mut B { @@ -197,6 +202,11 @@ impl Seek for Box { fn stream_position(&mut self) -> io::Result { (**self).stream_position() } + + #[inline] + fn stream_len(&mut self) -> io::Result { + (**self).stream_len() + } } #[stable(feature = "rust1", since = "1.0.0")] impl BufRead for Box {