From 95129706bcbaaf9c651b0226cd68561d2dd58387 Mon Sep 17 00:00:00 2001 From: Fabian Freyer Date: Mon, 28 Nov 2022 19:19:26 +0100 Subject: Bring BinaryReader.seek more in line with File Adds a `whence` parameter to BinaryReader.seek which behaves similarly to FileObjects seek method, but defaults to 0, keeping backwards compatibility. --- python/binaryview.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'python/binaryview.py') diff --git a/python/binaryview.py b/python/binaryview.py index eab2373a..c33d82c4 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -8460,11 +8460,12 @@ class BinaryReader: return None return struct.unpack(">Q", result)[0] - def seek(self, offset: int) -> None: + def seek(self, offset: int, whence: int = 0) -> None: """ ``seek`` update internal offset to ``offset``. :param int offset: offset to set the internal offset to + :param int whence: optional, defaults to 0 for absolute file positioning, or 1 for relative to current location :rtype: None :Example: @@ -8475,6 +8476,9 @@ class BinaryReader: '0x100000000L' >>> """ + if whence: + self.seek_relative(offset) + return core.BNSeekBinaryReader(self._handle, offset) def seek_relative(self, offset: int) -> None: -- cgit v1.3.1