code: def _untar(path, fname, delete=True, flatten=False):
      """
      Unpack the given archive file to the same directory.
  
      :param str path:
          The folder containing the archive. Will contain the contents.
  
      :param str fname:
          The filename of the archive file.
  
      :param bool delete:
          If true, the archive will be deleted after extraction.
      """
      import tarfile
  
      logging.debug(f"unpacking {fname}")
      fullpath = os.path.join(path, fname)
      # very painfully manually extract files so that we can use PathManger.open
      # instead, lest we are using fb internal file services
  
      with tarfile.open(fileobj=PathManager.open(fullpath, "rb")) as tf:
          for item in tf:
              item_name = item.name
              while item_name.startswith("./"):
                  # internal file systems will actually create a literal "."
                  # directory, so we gotta watch out for that
                  item_name = item_name[2:]
              if flatten:
                  # flatten the tar file if there are subdirectories
                  fn = os.path.join(path, os.path.split(item_name)[-1])
              else:
                  fn = os.path.join(path, item_name)
              logging.debug(f"Extracting to {fn}")
              if item.isdir():
                  PathManager.mkdirs(fn)
              elif item.isfile():
                  with PathManager.open(fn, "wb") as wf, tf.extractfile(
                      item.name
                  ) as rf:
                      tarfile.copyfileobj(rf, wf)
              else:
                  raise NotImplementedError(
                      "No support for symlinks etc. right now."
                  )
  
      if delete:
          try:
              PathManager.rm(fullpath)
          except PermissionError:
              logging.error(
                  f"Tried to delete {fullpath} but got a permission error. This "
                  "is known to happen in Windows and is probably not fatal."
              )
  
imports: import importlib
  import json
  import time
  import datetime
  import os
  import requests
  import shutil
  import hashlib
  import tqdm
  import gzip
  import math
  import contextlib
  import parlai.utils.logging
  from parlai.utils.io import PathManager
label_desc: Use image node_id 7 for calling a global function with example usage: _untar(path, fname, delete, flatten) without return types