def read(self, blocksize):  # pylint: disable=invalid-name
    """Returns data back to the HTTP post request."""
    if self.end_of_stream:
      return ""
    if self.read_header:
      # Read from header first.
      ret = self.header.read(blocksize)
      if ret:
        return ret
      self.read_header = False
    # Otherwise, read from the file, compress the data and return it.
    # Note that since we add a block size marker, we need subtract marker size.
    blocksize -= sutils.SIZE_PACKER.size
    while not self.buffered and not self.end_of_file:
      raw = self.fp.read(blocksize)
      if not raw:
        # We need to flush the compressor and send that data too.
        self.end_of_file = True
        self.buffered += self.compressor.flush()
        break
      # While compressing, we may not get anything immediatelly.
      compressed = self.compressor.compress(raw)
      if compressed:
        self.buffered += compressed
    if len(self.buffered) > blocksize:
      ret = self.buffered[:blocksize]
      self.buffered = self.buffered[blocksize:]
    else:
      ret = self.buffered
      self.buffered = ""
    if not ret:
      # Once the data is exhausted, we mark the end of the stream
      # and we simply return the 0 marker.
      self.end_of_stream = True
    # Return the size of the block plus the block itself.
    return sutils.SIZE_PACKER.pack(len(ret)) + ret
dataset/ETHPy150Open google/grr/grr/server/data_server/rebalance.py/FileCopyWrapper.read/original