Reads a chunk at a time. If the current position is within a chunk the remainder of the chunk is returned.
(self)
| 1603 | return True |
| 1604 | |
| 1605 | async def readchunk(self) -> bytes: |
| 1606 | """Reads a chunk at a time. If the current position is within a |
| 1607 | chunk the remainder of the chunk is returned. |
| 1608 | """ |
| 1609 | await self.open() |
| 1610 | received = len(self._buffer) - self._buffer_pos |
| 1611 | chunk_data = EMPTY |
| 1612 | chunk_size = int(self.chunk_size) |
| 1613 | |
| 1614 | if received > 0: |
| 1615 | chunk_data = self._buffer[self._buffer_pos :] |
| 1616 | elif self._position < int(self.length): |
| 1617 | chunk_number = int((received + self._position) / chunk_size) |
| 1618 | if self._chunk_iter is None: |
| 1619 | self._chunk_iter = _AsyncGridOutChunkIterator( |
| 1620 | self, self._chunks, self._session, chunk_number |
| 1621 | ) |
| 1622 | |
| 1623 | chunk = await self._chunk_iter.next() |
| 1624 | chunk_data = chunk["data"][self._position % chunk_size :] |
| 1625 | |
| 1626 | if not chunk_data: |
| 1627 | raise CorruptGridFile("truncated chunk") |
| 1628 | |
| 1629 | self._position += len(chunk_data) |
| 1630 | self._buffer = EMPTY |
| 1631 | self._buffer_pos = 0 |
| 1632 | return chunk_data |
| 1633 | |
| 1634 | async def _read_size_or_line(self, size: int = -1, line: bool = False) -> bytes: |
| 1635 | """Internal read() and readline() helper.""" |