Asynchronously read a number of bytes. If ``partial`` is true, data is returned as soon as we have any bytes to return (but never more than ``num_bytes``) .. versionchanged:: 4.0 Added the ``partial`` argument. The callback argument is now optional
(self, num_bytes: int, partial: bool = False)
| 398 | return future |
| 399 | |
| 400 | def read_bytes(self, num_bytes: int, partial: bool = False) -> Awaitable[bytes]: |
| 401 | """Asynchronously read a number of bytes. |
| 402 | |
| 403 | If ``partial`` is true, data is returned as soon as we have |
| 404 | any bytes to return (but never more than ``num_bytes``) |
| 405 | |
| 406 | .. versionchanged:: 4.0 |
| 407 | Added the ``partial`` argument. The callback argument is now |
| 408 | optional and a `.Future` will be returned if it is omitted. |
| 409 | |
| 410 | .. versionchanged:: 6.0 |
| 411 | |
| 412 | The ``callback`` and ``streaming_callback`` arguments have |
| 413 | been removed. Use the returned `.Future` (and |
| 414 | ``partial=True`` for ``streaming_callback``) instead. |
| 415 | |
| 416 | """ |
| 417 | future = self._start_read() |
| 418 | assert isinstance(num_bytes, numbers.Integral) |
| 419 | self._read_bytes = num_bytes |
| 420 | self._read_partial = partial |
| 421 | try: |
| 422 | self._try_inline_read() |
| 423 | except: |
| 424 | future.add_done_callback(lambda f: f.exception()) |
| 425 | raise |
| 426 | return future |
| 427 | |
| 428 | def read_into(self, buf: bytearray, partial: bool = False) -> Awaitable[int]: |
| 429 | """Asynchronously read a number of bytes. |