def __read_from_buffer(self, size):
    """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.
    """
    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
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.
    
mapreduce/lib/blobstore/blobstore.py