MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / readall

Method readall

tools/python-3.11.9-amd64/Lib/_pyio.py:1670–1703  ·  view source on GitHub ↗

Read all data from the file, returned as bytes. In non-blocking mode, returns as much as is immediately available, or None if no data is available. Return an empty bytes object at EOF.

(self)

Source from the content-addressed store, hash-verified

1668 return None
1669
1670 def readall(self):
1671 """Read all data from the file, returned as bytes.
1672
1673 In non-blocking mode, returns as much as is immediately available,
1674 or None if no data is available. Return an empty bytes object at EOF.
1675 """
1676 self._checkClosed()
1677 self._checkReadable()
1678 bufsize = DEFAULT_BUFFER_SIZE
1679 try:
1680 pos = os.lseek(self._fd, 0, SEEK_CUR)
1681 end = os.fstat(self._fd).st_size
1682 if end >= pos:
1683 bufsize = end - pos + 1
1684 except OSError:
1685 pass
1686
1687 result = bytearray()
1688 while True:
1689 if len(result) >= bufsize:
1690 bufsize = len(result)
1691 bufsize += max(bufsize, DEFAULT_BUFFER_SIZE)
1692 n = bufsize - len(result)
1693 try:
1694 chunk = os.read(self._fd, n)
1695 except BlockingIOError:
1696 if result:
1697 break
1698 return None
1699 if not chunk: # reached the end of the file
1700 break
1701 result += chunk
1702
1703 return bytes(result)
1704
1705 def readinto(self, b):
1706 """Same as RawIOBase.readinto()."""

Callers 3

readMethod · 0.95
_read_unlockedMethod · 0.45
readMethod · 0.45

Calls 4

_checkReadableMethod · 0.95
maxFunction · 0.85
_checkClosedMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected