code: def rewrite_tar(root_dir, tar_filepath):
      """Rewrite the older .tar file into new better compressed one.
  
      Compression formats supported by this method (.tar.gz, .tgz, .tar.bz2)
  
      Args:
        root_dir: directory path which contain tar compressed file
        tar_filepath: path from directory to file
      """
      # Create a tempfile to store the images contain noise
      with tempfile.TemporaryDirectory(
          dir=root_dir, suffix="fake"
      ) as temp_dir:
          # Checking the extension of file to be extract
          tar_filepath_lowercase = tar_filepath.lower()
          if tar_filepath_lowercase.endswith("gz"):
              extension = ":gz"
          elif tar_filepath_lowercase.endswith("bz2"):
              extension = ":bz2"
          elif tar_filepath_lowercase.endswith("xz"):
              extension = ":xz"
          else:
              extension = ""
  
          # Extraction of .tar file
          with tarfile.open(tar_filepath, "r" + extension) as tar:
              tar.extractall(path=temp_dir)
  
          rewrite_dir(
              temp_dir
          )  # Recursively compress the archive content
  
          # Convert back into tar file
          with tarfile.open(tar_filepath, "w" + extension) as tar:
              tar.add(temp_dir, arcname="", recursive=True)
  
file_path: datasets/tensorflow_datasets/scripts/replace_fake_images.py
imports: import hashlib
  import os
  import tarfile
  import tempfile
  import zipfile
  import zlib
  import absl.app
  import absl.flags
  import numpy
  import PIL.Image
label_desc: Use image node_id 3 for calling a global function with example usage: rewrite_tar(root_dir, tar_filepath) without return types