diff options
Diffstat (limited to 'buffered-reader/src/lib.rs')
-rw-r--r-- | buffered-reader/src/lib.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/buffered-reader/src/lib.rs b/buffered-reader/src/lib.rs index 951b8c71..7f082f72 100644 --- a/buffered-reader/src/lib.rs +++ b/buffered-reader/src/lib.rs @@ -152,6 +152,24 @@ pub trait BufferedReader : io::Read + fmt::Debug { return Ok(data); } + /// Like steal_eof, but instead of returning the data, the data is + /// discarded. + fn drop_eof(&mut self) -> Result<(), std::io::Error> { + loop { + match self.data_consume(DEFAULT_BUF_SIZE) { + Ok(ref buffer) => + if buffer.len() < DEFAULT_BUF_SIZE { + // EOF. + break; + }, + Err(err) => + return Err(err), + } + } + + Ok(()) + } + fn into_inner<'a>(self: Box<Self>) -> Option<Box<BufferedReader + 'a>> where Self: 'a; } @@ -234,6 +252,10 @@ impl <'a> BufferedReader for Box<BufferedReader + 'a> { return self.as_mut().steal_eof(); } + fn drop_eof(&mut self) -> Result<(), std::io::Error> { + return self.as_mut().drop_eof(); + } + fn into_inner<'b>(self: Box<Self>) -> Option<Box<BufferedReader + 'b>> where Self: 'b { // Strip the outer box. |