We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8ce12b5 commit 0518de7Copy full SHA for 0518de7
kaitaistruct.py
@@ -95,18 +95,20 @@ def pos(self):
95
return self._io.tell()
96
97
def size(self):
98
+ if hasattr(self, 'size_cached'):
99
+ return self.size_cached
100
# Python has no internal File object API function to get
101
# current file / StringIO size, thus we use the following
102
# trick.
103
io = self._io
104
# Remember our current position
105
cur_pos = io.tell()
106
# Seek to the end of the File object
- io.seek(0, SEEK_END)
107
# Remember position, which is equal to the full length
- full_size = io.tell()
108
+ full_size = io.seek(0, SEEK_END)
109
# Seek back to the current position
110
io.seek(cur_pos)
111
+ self.size_cached = full_size
112
return full_size
113
114
# ========================================================================
0 commit comments