MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / readchunk

Method readchunk

gridfs/asynchronous/grid_file.py:1605–1632  ·  view source on GitHub ↗

Reads a chunk at a time. If the current position is within a chunk the remainder of the chunk is returned.

(self)

Source from the content-addressed store, hash-verified

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."""

Callers 5

_read_size_or_lineMethod · 0.95
test_readchunkMethod · 0.95
download_to_streamMethod · 0.45

Calls 4

openMethod · 0.95
CorruptGridFileClass · 0.90
nextMethod · 0.45

Tested by 2

test_readchunkMethod · 0.76