code: def compress(data, compression, width, height, depth, version=1):
      
      if compression == Compression.RAW:
          result = data
      elif compression == Compression.PACK_BITS:
          result = encode_packbits(data, width, height, depth, version)
      elif compression == Compression.ZIP:
          result = zlib.compress(data)
      else:
          encoded = encode_prediction(data, width, height, depth)
          result = zlib.compress(encoded)
  
      return result
docs: Compress raw data.
  
      :param data: raw data bytes to write.
      :param compression: compression type, see :py:class:`.Compression`.
      :param width: width.
      :param height: height.
      :param depth: bit depth of the pixel.
      :param version: psd file version.
      :return: compressed data bytes.