MCPcopy Create free account
hub / github.com/aws/aws-cli / _read

Method _read

awscli/s3transfer/upload.py:445–485  ·  view source on GitHub ↗

Reads a specific amount of data from a stream and returns it. If there is any data in initial_data, that will be popped out first. :type fileobj: A file-like object that implements read :param fileobj: The stream to read from. :type amount: int :par

(self, fileobj, amount, truncate=True)

Source from the content-addressed store, hash-verified

443 yield part_number, part_object
444
445 def _read(self, fileobj, amount, truncate=True):
446 """
447 Reads a specific amount of data from a stream and returns it. If there
448 is any data in initial_data, that will be popped out first.
449
450 :type fileobj: A file-like object that implements read
451 :param fileobj: The stream to read from.
452
453 :type amount: int
454 :param amount: The number of bytes to read from the stream.
455
456 :type truncate: bool
457 :param truncate: Whether or not to truncate initial_data after
458 reading from it.
459
460 :return: Generator which generates part bodies from the initial data.
461 """
462 # If the the initial data is empty, we simply read from the fileobj
463 if len(self._initial_data) == 0:
464 return fileobj.read(amount)
465
466 # If the requested number of bytes is less than the amount of
467 # initial data, pull entirely from initial data.
468 if amount <= len(self._initial_data):
469 data = self._initial_data[:amount]
470 # Truncate initial data so we don't hang onto the data longer
471 # than we need.
472 if truncate:
473 self._initial_data = self._initial_data[amount:]
474 return data
475
476 # At this point there is some initial data left, but not enough to
477 # satisfy the number of bytes requested. Pull out the remaining
478 # initial data and read the rest from the fileobj.
479 amount_to_read = amount - len(self._initial_data)
480 data = self._initial_data + fileobj.read(amount_to_read)
481
482 # Zero out initial data so we don't hang onto the data any more.
483 if truncate:
484 self._initial_data = b''
485 return data
486
487 def _wrap_data(self, data, callbacks, close_callbacks):
488 """

Callers 2

Calls 1

readMethod · 0.45

Tested by

no test coverage detected