class_docstr: The XarFile Class provides an interface to tar/rar/zip archives.
  
  Args:
      name(str) : file or directory name to be archived
      mode(str) : specifies the mode in which the file is opened, it must be:
          ========   ==============================================================================================
          Charater   Meaning
          --------   ----------------------------------------------------------------------------------------------
          'r'        open for reading
          'w'        open for writing, truncating the file first, file will be saved according to the arctype field
          'a'        open for writing, appending to the end of the file if it exists
          ========   ===============================================================================================
      arctype(str) : archive type, support ['tar' 'rar' 'zip' 'tar.gz' 'tar.bz2' 'tar.xz' 'tgz' 'txz'], if
                     the mode if 'w' or 'a', the default is 'tar', if the mode is 'r', it will be based on actual
                     archive type of file
class_docstr_tok: ["The","XarFile","Class","provides","an","interface","to","tar\/rar\/zip","archives",".","Args",":","name","(","str",")",":","file","or","directory","name","to","be","archived","mode","(","str",")",":","specifies","the","mode","in","which","the","file","is","opened",",","it","must","be",":","========","==============================================================================================","Charater","Meaning","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","--","'","r","'","open","for","reading","'","w","'","open","for","writing",",","truncating","the","file","first",",","file","will","be","saved","according","to","the","arctype","field","'","a","'","open","for","writing",",","appending","to","the","end","of","the","file","if","it","exists","========","===============================================================================================","arctype","(","str",")",":","archive","type",",","support","[","'tar","'","'rar","'","'zip","'","'tar.gz","'","'tar.bz2","'","'tar.xz","'","'tgz","'","'txz","'","]",",","if","the","mode","if","'","w","'","or","'","a","'",",","the","default","is","'tar","'",",","if","the","mode","is","'","r","'",",","it","will","be","based","on","actual","archive","type","of","file"]
docstr: Add the file `name' to the archive. `name' may be any type of file (directory, fifo, symbolic link, etc.).
  If given, `arcname' specifies an alternative name for the file in the archive. Directories are added
  recursively by default. This can be avoided by setting `recursive' to False. `exclude' is a function that
  should return True for each filename to be excluded.
docstr_tok: ["Add","the","file","`","name","'","to","the","archive",".","`","name","'","may","be","any","type","of","file","(","directory",",","fifo",",","symbolic","link",",","etc.",")",".","If","given",",","`","arcname","'","specifies","an","alternative","name","for","the","file","in","the","archive",".","Directories","are","added","recursively","by","default",".","This","can","be","avoided","by","setting","`","recursive","'","to","False",".","`","exclude","'","is","a","function","that","should","return","True","for","each","filename","to","be","excluded","."]
code: def add(
      self,
      name: str,
      arcname: str = None,
      recursive: bool = True,
      exclude: Callable = None,
  ):
      """
      Add the file `name' to the archive. `name' may be any type of file (directory, fifo, symbolic link, etc.).
      If given, `arcname' specifies an alternative name for the file in the archive. Directories are added
      recursively by default. This can be avoided by setting `recursive' to False. `exclude' is a function that
      should return True for each filename to be excluded.
      """
      if self.arctype == "tar":
          self._archive_fp.add(name, arcname, recursive, filter=exclude)
      else:
          self._archive_fp.write(name)
          if not recursive or not os.path.isdir(name):
              return
          items = []
          for _d, _sub_ds, _files in os.walk(name):
              items += [os.path.join(_d, _file) for _file in _files]
              items += [os.path.join(_d, _sub_d) for _sub_d in _sub_ds]
  
          for item in items:
              if exclude and not exclude(item):
                  continue
              self._archive_fp.write(item)
  
imports: import os
  import tarfile
  import zipfile
  from typing import List, Generator, Callable
  import rarfile
label_desc: Use image node_id 5 for calling the XarFile obj's underlying member method code with example usage: obj.add(name, arcname, recursive, exclude) without return types