File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed
Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -649,15 +649,23 @@ def _safe_read(self, amt):
649649 """
650650 cursize = min (amt , _MIN_READ_BUF_SIZE )
651651 data = self .fp .read (cursize )
652- while len (data ) < amt :
653- if len (data ) < cursize :
654- raise IncompleteRead (data , amt - len (data ))
652+ if len (data ) >= amt :
653+ return data
654+ if len (data ) < cursize :
655+ raise IncompleteRead (data , amt - len (data ))
656+
657+ data = io .BytesIO (data )
658+ data .seek (0 , 2 )
659+ while True :
655660 # This is a geometric increase in read size (never more than
656661 # doubling out the current length of data per loop iteration).
657662 delta = min (cursize , amt - cursize )
658- data += self .fp .read (delta )
663+ data .write (self .fp .read (delta ))
664+ if data .tell () >= amt :
665+ return data .getvalue ()
659666 cursize += delta
660- return data
667+ if data .tell () < cursize :
668+ raise IncompleteRead (data .getvalue (), amt - data .tell ())
661669
662670 def _safe_readinto (self , b ):
663671 """Same as _safe_read, but for reading into a buffer."""
You can’t perform that action at this time.
0 commit comments