code: def write_file(infile: str,
                 outfile: str,
                 progress_callback: Callable[[float], None],
                 chunk_size: int = 1024,
                 file_size: int = None):
      
      total_written = 0
      with open(infile, 'rb') as img, open(outfile, 'wb') as part:
          if None is file_size:
              file_size = img.seek(0, 2)
              img.seek(0)
              LOG.info(f'write_file: file size calculated as {file_size}B')
          LOG.info(f'write_file: writing {infile} ({file_size}B)'
                   f' to {outfile} in {chunk_size}B chunks')
          while True:
              chunk = img.read(chunk_size)
              part.write(chunk)
              total_written += len(chunk)
              progress_callback(total_written / file_size)
              if len(chunk) != chunk_size:
                  break
docs: Write a file to another file with progress callbacks.
  
      :param infile: The input filepath
      :param outfile: The output filepath
      :param progress_callback: The callback to call for progress
      :param chunk_size: The size of file chunks to copy in between progress
                         notifications
      :param file_size: The total size of the update file (for generating
                        progress percentage). If ``None``, generated with
                        ``seek``/``tell``.