Skip to content

Commit

Permalink
Improve EOF processing for potential re-reading
Browse files Browse the repository at this point in the history
  • Loading branch information
Evgeny Khramtsov committed Jun 29, 2024
1 parent 4b22c17 commit 0d4d569
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/reading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,16 @@ impl<T :io::Read + io::Seek> PacketReader<T> {
if let Some(pck) = self.base_pck_rdr.read_packet() {
return Ok(Some(pck));
}
let page = tri!(self.read_ogg_page());
// Save the current position to rewind if EOF is reached.
let pos = tri!(self.rdr.stream_position());
let page = tri!(match self.read_ogg_page() {
Err(OggReadError::ReadError(e)) if e.kind() == ErrorKind::UnexpectedEof => {
// Rewind to the saved position to allow for potential re-reading.
self.rdr.seek(SeekFrom::Start(pos))?;
Err(OggReadError::ReadError(e))
}
ret => ret,
});
match page {
Some(page) => tri!(self.base_pck_rdr.push_page(page)),
None => return Ok(None),
Expand Down

0 comments on commit 0d4d569

Please sign in to comment.