'Reads at most size bytes from the buffer.
Args:
size: Number of bytes to read, or negative to read the entire buffer.
Returns:
Tuple (data, size):
data: The bytes read from the buffer.
size: The remaining unread byte count. Negative when size
is negative. Thus when remaining size != 0, the calling method
may choose to fill the buffer again and keep reading.'

def __read_from_buffer(self, size):

    if (not self.__blob_key):
        raise ValueError('File    is    closed')
    if (size < 0):
        end_pos = len(self.__buffer)
    else:
        end_pos = (self.__buffer_position + size)
    data = self.__buffer[self.__buffer_position:end_pos]
    data_length = len(data)
    size -= data_length
    self.__position += data_length
    self.__buffer_position += data_length
    if (self.__buffer_position == len(self.__buffer)):
        self.__buffer = ''
        self.__buffer_position = 0
    return (data, size)
