File tree 2 files changed +9
-20
lines changed 2 files changed +9
-20
lines changed Original file line number Diff line number Diff line change @@ -1674,31 +1674,22 @@ def readall(self):
1674
1674
except OSError :
1675
1675
pass
1676
1676
1677
- result = bytearray (bufsize )
1678
- bytes_read = 0
1677
+ result = bytearray ()
1679
1678
while True :
1680
- if bytes_read >= bufsize :
1681
- # Parallels _io/fileio.c new_buffersize
1682
- if bufsize > 65536 :
1683
- addend = bufsize >> 3
1684
- else :
1685
- addend = bufsize + 256
1686
- if addend < DEFAULT_BUFFER_SIZE :
1687
- addend = DEFAULT_BUFFER_SIZE
1688
- bufsize += addend
1689
- result [bytes_read :bufsize ] = b'\0 '
1690
- assert bufsize - bytes_read > 0 , "Should always try and read at least one byte"
1679
+ if len (result ) >= bufsize :
1680
+ bufsize = len (result )
1681
+ bufsize += max (bufsize , DEFAULT_BUFFER_SIZE )
1682
+ n = bufsize - len (result )
1691
1683
try :
1692
- n = os .readinto (self ._fd , memoryview ( result )[ bytes_read :] )
1684
+ chunk = os .read (self ._fd , n )
1693
1685
except BlockingIOError :
1694
- if bytes_read > 0 :
1686
+ if result :
1695
1687
break
1696
1688
return None
1697
- if n == 0 : # reached the end of the file
1689
+ if not chunk : # reached the end of the file
1698
1690
break
1699
- bytes_read += n
1691
+ result += chunk
1700
1692
1701
- del result [bytes_read :]
1702
1693
return bytes (result )
1703
1694
1704
1695
def readinto (self , buffer ):
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments