code: def decompress(fr, to, codec=None, fopen=open, threads=1):
      def iter_chunks():
          with fopen(fr, "rb") as f:
              cnt = 0
  
              while True:
                  ll = f.read(4)
  
                  if ll:
                      ll = struct.unpack("<I", ll)[0]
  
                  if ll:
                      if ll > 100000000:
                          raise Exception("broken stream")
  
                      yield f.read(ll)
  
                      cnt += ll
                  else:
                      if not cnt:
                          raise Exception("empty stream")
  
                      return
  
      it = iter_chunks()
      extra = []
  
      for chunk in it:
          hdr = {}
  
          try:
              hdr = json.loads(chunk)
          except Exception as e:
              logger.info(
                  "can not parse header, suspect old format: %s", e
              )
              extra.append(chunk)
  
          break
  
      def resolve_codec():
          if "codec" in hdr:
              return find_codec(hdr["codec"])
  
          if codec:
              return find_codec(codec)
  
          return codec_for(fr)
  
      dc = resolve_codec()["d"]
  
      def iter_all_chunks():
          for x in extra:
              yield x
  
          for x in it:
              yield x
  
      with fopen(to, "wb") as f:
          for c in lpp.par_apply(iter_all_chunks(), dc, threads):
              if c:
                  logger.debug("complete %s", len(c))
                  f.write(c)
              else:
                  break
  
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 5 for calling a global function with example usage: decompress(fr, to, codec, fopen, threads) and returns: codec_for, find_codec, find_codec