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):
9595 return self ._io .tell ()
9696
9797 def size (self ):
98+ if hasattr (self , 'size_cached' ):
99+ return self .size_cached
98100 # Python has no internal File object API function to get
99101 # current file / StringIO size, thus we use the following
100102 # trick.
101103 io = self ._io
102104 # Remember our current position
103105 cur_pos = io .tell ()
104106 # Seek to the end of the File object
105- io .seek (0 , SEEK_END )
106107 # Remember position, which is equal to the full length
107- full_size = io .tell ( )
108+ full_size = io .seek ( 0 , SEEK_END )
108109 # Seek back to the current position
109110 io .seek (cur_pos )
111+ self .size_cached = full_size
110112 return full_size
111113
112114 # ========================================================================
You can’t perform that action at this time.
0 commit comments