Class to read data out of GridFS.
| 1451 | |
| 1452 | |
| 1453 | class AsyncGridOut(GRIDOUT_BASE_CLASS): # type: ignore |
| 1454 | |
| 1455 | """Class to read data out of GridFS.""" |
| 1456 | |
| 1457 | def __init__( |
| 1458 | self, |
| 1459 | root_collection: AsyncCollection[Any], |
| 1460 | file_id: Optional[int] = None, |
| 1461 | file_document: Optional[Any] = None, |
| 1462 | session: Optional[AsyncClientSession] = None, |
| 1463 | ) -> None: |
| 1464 | """Read a file from GridFS |
| 1465 | |
| 1466 | Application developers should generally not need to |
| 1467 | instantiate this class directly - instead see the methods |
| 1468 | provided by :class:`~gridfs.GridFS`. |
| 1469 | |
| 1470 | Either `file_id` or `file_document` must be specified, |
| 1471 | `file_document` will be given priority if present. Raises |
| 1472 | :class:`TypeError` if `root_collection` is not an instance of |
| 1473 | :class:`~pymongo.collection.AsyncCollection`. |
| 1474 | |
| 1475 | :param root_collection: root collection to read from |
| 1476 | :param file_id: value of ``"_id"`` for the file to read |
| 1477 | :param file_document: file document from |
| 1478 | `root_collection.files` |
| 1479 | :param session: a |
| 1480 | :class:`~pymongo.client_session.AsyncClientSession` to use for all |
| 1481 | commands |
| 1482 | |
| 1483 | .. versionchanged:: 3.8 |
| 1484 | For better performance and to better follow the GridFS spec, |
| 1485 | :class:`GridOut` now uses a single cursor to read all the chunks in |
| 1486 | the file. |
| 1487 | |
| 1488 | .. versionchanged:: 3.6 |
| 1489 | Added ``session`` parameter. |
| 1490 | |
| 1491 | .. versionchanged:: 3.0 |
| 1492 | Creating a GridOut does not immediately retrieve the file metadata |
| 1493 | from the server. Metadata is fetched when first needed. |
| 1494 | """ |
| 1495 | if not isinstance(root_collection, AsyncCollection): |
| 1496 | raise TypeError( |
| 1497 | f"root_collection must be an instance of AsyncCollection, not {type(root_collection)}" |
| 1498 | ) |
| 1499 | _disallow_transactions(session) |
| 1500 | |
| 1501 | root_collection = _clear_entity_type_registry(root_collection) |
| 1502 | |
| 1503 | super().__init__() |
| 1504 | |
| 1505 | self._chunks = root_collection.chunks |
| 1506 | self._files = root_collection.files |
| 1507 | self._file_id = file_id |
| 1508 | self._buffer = EMPTY |
| 1509 | # Start position within the current buffered chunk. |
| 1510 | self._buffer_pos = 0 |