Skip to content

Commit 452e843

Browse files
committed
seek() using relative offsets, not tell()
1 parent 5dfb881 commit 452e843

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

kaitaistruct.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import itertools
22
import sys
33
import struct
4-
from io import BytesIO # noqa
4+
import io
5+
from io import BytesIO, SEEK_CUR, SEEK_END # noqa
56

67
PY2 = sys.version_info[0] == 2
78

@@ -71,7 +72,7 @@ def is_eof(self):
7172
if t == b'':
7273
return True
7374
else:
74-
io.seek(io.tell() - 1)
75+
io.seek(-1, SEEK_CUR)
7576
return False
7677

7778
def seek(self, n):
@@ -88,7 +89,7 @@ def size(self):
8889
# Remember our current position
8990
cur_pos = io.tell()
9091
# Seek to the end of the File object
91-
io.seek(0, 2)
92+
io.seek(0, SEEK_END)
9293
# Remember position, which is equal to the full length
9394
full_size = io.tell()
9495
# Seek back to the current position
@@ -287,7 +288,7 @@ def read_bytes_term(self, term, include_term, consume_term, eos_error):
287288
if include_term:
288289
r += c
289290
if not consume_term:
290-
self._io.seek(self._io.tell() - 1)
291+
self._io.seek(-1, SEEK_CUR)
291292
return r
292293
else:
293294
r += c

0 commit comments

Comments
 (0)