From 487e92711628885d0df6f95dbf3a57d0f777f67c Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 3 Dec 2020 12:47:43 +0100 Subject: [PATCH] historian: Make the GossipStream seekable --- historian/cli/common.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/historian/cli/common.py b/historian/cli/common.py index 4e695ad..3c0a029 100644 --- a/historian/cli/common.py +++ b/historian/cli/common.py @@ -57,6 +57,21 @@ class GossipStream: assert header[:3] == b"GSP" assert header[3] == 1 + def seek(self, offset): + """Allow skipping to a specific point in the stream. + + The offset is denoted in bytes from the start, including the + header, and matches the value of f.tell() + """ + self.stream.seek(offset, io.SEEK_SET) + + def tell(self): + """Returns the absolute position in the stream. + + Includes the header, and matches f.seek() + """ + return self.stream.tell() + def __iter__(self): return self