From 20d33df4586d1a94008b80729f00fe1a1b1fd132 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Mon, 10 Apr 2023 20:37:55 -0400 Subject: [PATCH] flv: Add `skip_back` method for reverse tag parsing --- flv/src/tag.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/flv/src/tag.rs b/flv/src/tag.rs index 77f738ce4..3d313a7cb 100644 --- a/flv/src/tag.rs +++ b/flv/src/tag.rs @@ -83,6 +83,20 @@ impl<'a> Tag<'a> { None } } + + /// Skip back to the prior tag in the FLV. + /// + /// FLV files are constructed as a list of tags. Back pointers to prior + /// tags are provided to allow reverse seeking. This function ignores the + /// tag at the current location and skips back to prior data in the file. + pub fn skip_back(reader: &mut FlvReader<'a>) -> Option<()> { + let previous_tag_size = reader.read_u32()?; + reader + .seek(SeekFrom::Current(-(previous_tag_size as i64))) + .ok()?; + + Some(()) + } } #[cfg(test)]