in src/base64io/__init__.py [0:0]
def _read_additional_data_removing_whitespace(self, data, total_bytes_to_read):
# type: (bytes, int) -> bytes
"""Read additional data from wrapped stream until we reach the desired number of bytes.
.. note::
All whitespace is ignored.
:param bytes data: Data that has already been read from wrapped stream
:param int total_bytes_to_read: Number of total non-whitespace bytes to read from wrapped stream
:returns: ``total_bytes_to_read`` bytes from wrapped stream with no whitespace
:rtype: bytes
"""
if total_bytes_to_read is None:
# If the requested number of bytes is None, we read the entire message, in which
# case the base64 module happily removes any whitespace.
return data
_data_buffer = io.BytesIO()
_data_buffer.write(b"".join(data.split()))
_remaining_bytes_to_read = total_bytes_to_read - _data_buffer.tell()
while _remaining_bytes_to_read > 0:
_raw_additional_data = _to_bytes(self.__wrapped.read(_remaining_bytes_to_read))
if not _raw_additional_data:
# No more data to read from wrapped stream.
break
_data_buffer.write(b"".join(_raw_additional_data.split()))
_remaining_bytes_to_read = total_bytes_to_read - _data_buffer.tell()
return _data_buffer.getvalue()