code: def tar(
      paths,
      output,
      compression_filter=None,
      compression_level=None,
      fixed_mtime=None,
      onerror=None,
      postprocess=None,
      dereference=False,
  ):
      if isinstance(paths, six.string_types):
          paths = [paths]
  
      if isinstance(output, six.string_types):
          temp_tar_path, stream = (
              output
              + "."
              + "".join(random.sample(string.ascii_lowercase, 8)),
              None,
          )
      else:
          temp_tar_path, stream = None, output
  
      compression_level = get_compression_level(
          compression_filter, compression_level
      )
  
      try:
          if compression_filter:
              filter_name = compression_filter
              if compression_level is not None:
                  filter_opts = {
                      "compression-level": str(compression_level)
                  }
              else:
                  filter_opts = {}
              # force gzip don't store mtime of the original file being compressed (http://www.gzip.org/zlib/rfc-gzip.html#file-format)
              if fixed_mtime is not None and compression_filter == GZIP:
                  filter_opts["timestamp"] = ""
          else:
              filter_name = filter_opts = None
  
          with libarchive.Archive(
              stream or temp_tar_path,
              mode="wb",
              format="gnu",
              filter=filter_name,
              filter_opts=filter_opts,
              fixed_mtime=fixed_mtime,
          ) as tarfile:
              # determine order if fixed_mtime is specified to produce stable archive
              paths = paths if fixed_mtime is None else sorted(paths)
  
              for p in paths:
                  if type(p) == tuple:
                      path, arcname = p
                  else:
                      path, arcname = p, os.path.basename(p)
  
                  if os.path.isdir(path):
                      for root, dirs, files in os.walk(
                          path, followlinks=dereference
                      ):
                          if fixed_mtime is None:
                              entries = dirs + files
                          else:
                              entries = sorted(dirs) + sorted(files)
  
                          reldir = os.path.relpath(root, path)
                          for f in entries:
                              _writepath(
                                  tarfile,
                                  os.path.join(root, f),
                                  os.path.normpath(
                                      os.path.join(arcname, reldir, f)
                                  ),
                                  onerror,
                                  postprocess,
                                  dereference,
                              )
                  else:
                      if not os.path.exists(path):
                          raise OSError(
                              "Specified path doesn't exist: {}".format(
                                  path
                              )
                          )
                      _writepath(
                          tarfile,
                          path,
                          arcname,
                          onerror,
                          postprocess,
                          dereference,
                      )
  
          if temp_tar_path:
              os.rename(temp_tar_path, output)
      except Exception:
          if temp_tar_path and os.path.exists(temp_tar_path):
              os.remove(temp_tar_path)
          raise
  
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 5 for calling a global function with example usage: tar(paths, output, compression_filter, compression_level, fixed_mtime, onerror, postprocess, dereference) without return types