code: def compress_file(filepath, compression="gz"):
      
      if compression not in ["gz", "bz2"]:
          raise ValueError("Supported compression formats are 'gz' and 'bz2'.")
      from monty.io import zopen
      if not filepath.lower().endswith(".%s" % compression):
          with open(filepath, 'rb') as f_in, \
                  zopen('%s.%s' % (filepath, compression), 'wb') as f_out:
              f_out.writelines(f_in)
          os.remove(filepath)
docs: Compresses a file with the correct extension. Functions like standard
      Unix command line gzip and bzip2 in the sense that the original
      uncompressed files are not retained.
  
      Args:
          filepath (str): Path to file.
          compression (str): A compression mode. Valid options are "gz" or
              "bz2". Defaults to "gz".