code: def _repack_archive (archive1, archive2, verbosity=0, interactive=True):
      
      format1, compression1 = get_archive_format(archive1)
      format2, compression2 = get_archive_format(archive2)
      if format1 == format2 and compression1 == compression2:
          # same format and compression allows to copy the file
          util.link_or_copy(archive1, archive2, verbosity=verbosity)
          return
      tmpdir = util.tmpdir()
      try:
          kwargs = dict(verbosity=verbosity, outdir=tmpdir)
          same_format = (format1 == format2 and compression1 and compression2)
          if same_format:
              # only decompress since the format is the same
              kwargs['format'] = compression1
          path = _extract_archive(archive1, **kwargs)
          archive = os.path.abspath(archive2)
          files = tuple(os.listdir(path))
          olddir = os.getcwd()
          os.chdir(path)
          try:
              kwargs = dict(verbosity=verbosity, interactive=interactive)
              if same_format:
                  # only compress since the format is the same
                  kwargs['format'] = compression2
              _create_archive(archive, files, **kwargs)
          finally:
              os.chdir(olddir)
      finally:
          shutil.rmtree(tmpdir, onerror=rmtree_log_error)
docs: Repackage an archive to a different format.