in src/aws_encryption_sdk/streaming_client.py [0:0]
def read(self, b=-1):
"""Returns either the requested number of bytes or the entire stream.
:param int b: Number of bytes to read
:returns: Processed (encrypted or decrypted) bytes from source stream
:rtype: bytes
"""
# Any negative value for b is interpreted as a full read
# None is also accepted for legacy compatibility
if b is None or b < 0:
b = -1
_LOGGER.debug("Stream read called, requesting %d bytes", b)
output = io.BytesIO()
if not self._message_prepped:
self._prep_message()
if self.closed: # dynamic values confuse pylint: disable=using-constant-test
raise ValueError("I/O operation on closed file")
if b >= 0:
self._read_bytes(b)
output.write(self.output_buffer[:b])
self.output_buffer = self.output_buffer[b:]
else:
while True:
line = self.readline()
if not line:
break
output.write(line)
self.bytes_read += output.tell()
_LOGGER.debug("Returning %d bytes of %d bytes requested", output.tell(), b)
return output.getvalue()