From 2dc8e72a479331894b1ad889d03162823729a691 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 24 Sep 2024 13:36:30 -0500 Subject: [PATCH] feat(stream): Allow reseting streams to an absolute position Inspired by #593 which is trying to use `winnow` for HDF5 --- src/stream/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/stream/mod.rs b/src/stream/mod.rs index 6ff53317..7d1459b7 100644 --- a/src/stream/mod.rs +++ b/src/stream/mod.rs @@ -129,6 +129,21 @@ where } } +impl Located +where + I: Clone + Stream + Offset, +{ + /// Reset the stream to the start + /// + /// This is useful for formats that encode a graph with addresses relative to the start of the + /// input. + #[doc(alias = "fseek")] + pub fn reset_to_start(&mut self) { + let start = self.initial.checkpoint(); + self.input.reset(&start); + } +} + impl AsRef for Located { #[inline(always)] fn as_ref(&self) -> &I {