code: def extract_tar(
      tar_file_path,
      output_dir,
      strip_components=None,
      fail_on_duplicates=True,
  ):
      output_dir = encode(output_dir, ENCODING)
      _make_dirs(output_dir)
      with libarchive.Archive(tar_file_path, mode="rb") as tarfile:
          for e in tarfile:
              p = _strip_prefix(e.pathname, strip_components)
              if not p:
                  continue
              dest = os.path.join(output_dir, encode(p, ENCODING))
              if e.pathname.endswith("/") or e.isdir():
                  _make_dirs(dest)
                  continue
  
              if strip_components and fail_on_duplicates:
                  if os.path.exists(dest):
                      raise Exception(
                          "The file {} is duplicated because of strip_components={}".format(
                              dest, strip_components
                          )
                      )
  
              _make_dirs(os.path.dirname(dest))
  
              if e.ishardlink():
                  src = os.path.join(
                      output_dir,
                      _strip_prefix(e.hardlink, strip_components),
                  )
                  _hardlink(src, dest)
                  continue
              if e.issym():
                  src = _strip_prefix(e.linkname, strip_components)
                  _symlink(src, dest)
                  continue
  
              with open(dest, "wb") as f:
                  if hasattr(os, "fchmod"):
                      os.fchmod(f.fileno(), e.mode & 0o7777)
                  libarchive.call_and_check(
                      _libarchive.archive_read_data_into_fd,
                      tarfile._a,
                      tarfile._a,
                      f.fileno(),
                  )
  
imports: import errno
  import logging
  import os
  import random
  import shutil
  import stat
  import string
  import sys
  import six
  import libarchive
  import libarchive._libarchive
  from pathlib2 import PurePath
label_desc: Use image node_id 3 for calling a global function with example usage: extract_tar(tar_file_path, output_dir, strip_components, fail_on_duplicates) without return types