code: def compress(fr, to, codec=None, fopen=open, threads=1):
      if codec:
          codec = find_codec(codec)
      else:
          codec = codec_for(to)
  
      func = codec["c"]
  
      def iter_blocks():
          with fopen(fr, "rb") as f:
              while True:
                  chunk = f.read(16 * 1024 * 1024)
  
                  if chunk:
                      yield chunk
                  else:
                      yield b""
  
                      return
  
      def iter_results():
          info = {
              "codec": codec["n"],
          }
  
          if fr:
              info["size"] = os.path.getsize(fr)
  
          yield json.dumps(info, sort_keys=True) + "\n"
  
          for c in lpp.par_apply(iter_blocks(), func, threads):
              yield c
  
      with fopen(to, "wb") as f:
          for c in iter_results():
              logger.debug("complete %s", len(c))
              f.write(struct.pack("<I", len(c)))
  
              try:
                  f.write(c)
              except TypeError:
                  f.write(c.encode("utf-8"))
  
file_path: catboost/library/python/compress/__init__.py
imports: from io import open
  import struct
  import json
  import os
  import logging
  import library.python.par_apply
  import library.python.codecs
label_desc: Use image node_id 4 for calling a global function with example usage: compress(fr, to, codec, fopen, threads) without return types