MCPcopy Create free account
hub / github.com/EasyIME/PIME / read_into

Method read_into

python/python3/tornado/iostream.py:431–478  ·  view source on GitHub ↗

Asynchronously read a number of bytes. ``buf`` must be a writable buffer into which data will be read. If ``partial`` is true, the callback is run as soon as any bytes have been read. Otherwise, it is run when the ``buf`` has been entirely filled with read data.

(self, buf: bytearray, partial: bool = False)

Source from the content-addressed store, hash-verified

429 return future
430
431 def read_into(self, buf: bytearray, partial: bool = False) -> Awaitable[int]:
432 """Asynchronously read a number of bytes.
433
434 ``buf`` must be a writable buffer into which data will be read.
435
436 If ``partial`` is true, the callback is run as soon as any bytes
437 have been read. Otherwise, it is run when the ``buf`` has been
438 entirely filled with read data.
439
440 .. versionadded:: 5.0
441
442 .. versionchanged:: 6.0
443
444 The ``callback`` argument was removed. Use the returned
445 `.Future` instead.
446
447 """
448 future = self._start_read()
449
450 # First copy data already in read buffer
451 available_bytes = self._read_buffer_size
452 n = len(buf)
453 if available_bytes >= n:
454 end = self._read_buffer_pos + n
455 buf[:] = memoryview(self._read_buffer)[self._read_buffer_pos : end]
456 del self._read_buffer[:end]
457 self._after_user_read_buffer = self._read_buffer
458 elif available_bytes > 0:
459 buf[:available_bytes] = memoryview(self._read_buffer)[
460 self._read_buffer_pos :
461 ]
462
463 # Set up the supplied buffer as our temporary read buffer.
464 # The original (if it had any data remaining) has been
465 # saved for later.
466 self._user_read_buffer = True
467 self._read_buffer = buf
468 self._read_buffer_pos = 0
469 self._read_buffer_size = available_bytes
470 self._read_bytes = n
471 self._read_partial = partial
472
473 try:
474 self._try_inline_read()
475 except:
476 future.add_done_callback(lambda f: f.exception())
477 raise
478 return future
479
480 def read_until_close(self) -> Awaitable[bytes]:
481 """Asynchronously reads all data from the socket until it is closed.

Callers 4

test_read_intoMethod · 0.80
consumeMethod · 0.80

Calls 2

_start_readMethod · 0.95
_try_inline_readMethod · 0.95

Tested by 4

test_read_intoMethod · 0.64
consumeMethod · 0.64