File tree Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Expand file tree Collapse file tree 1 file changed +4
-2
lines changed Original file line number Diff line number Diff line change @@ -95,18 +95,20 @@ def pos(self):
95
95
return self ._io .tell ()
96
96
97
97
def size (self ):
98
+ if hasattr (self , 'size_cached' ):
99
+ return self .size_cached
98
100
# Python has no internal File object API function to get
99
101
# current file / StringIO size, thus we use the following
100
102
# trick.
101
103
io = self ._io
102
104
# Remember our current position
103
105
cur_pos = io .tell ()
104
106
# Seek to the end of the File object
105
- io .seek (0 , SEEK_END )
106
107
# Remember position, which is equal to the full length
107
- full_size = io .tell ( )
108
+ full_size = io .seek ( 0 , SEEK_END )
108
109
# Seek back to the current position
109
110
io .seek (cur_pos )
111
+ self .size_cached = full_size
110
112
return full_size
111
113
112
114
# ========================================================================
You can’t perform that action at this time.
0 commit comments