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"]
code: def __init__(
      self, name: str, mode: str, arctype: str = "tar", **kwargs
  ):
      # if mode is 'w', adjust mode according to arctype field
      if mode == "w":
          if arctype in ["tar.gz", "tgz"]:
              mode = "w:gz"
              self.arctype = "tar"
          elif arctype == "tar.bz2":
              mode = "w:bz2"
              self.arctype = "tar"
          elif arctype in ["tar.xz", "txz"]:
              mode = "w:xz"
              self.arctype = "tar"
          else:
              self.arctype = arctype
      # if mode is 'r', adjust mode according to actual archive type of file
      elif mode == "r":
          if tarfile.is_tarfile(name):
              self.arctype = "tar"
              mode = "r:*"
          elif zipfile.is_zipfile(name):
              self.arctype = "zip"
          elif rarfile.is_rarfile(name):
              self.arctype = "rar"
      elif mode == "a":
          self.arctype = arctype
      else:
          raise RuntimeError("Unsupported mode {}".format(mode))
  
      if self.arctype in [
          "tar.gz",
          "tar.bz2",
          "tar.xz",
          "tar",
          "tgz",
          "txz",
      ]:
          self._archive_fp = tarfile.open(name, mode, **kwargs)
      elif self.arctype == "zip":
          self._archive_fp = zipfile.ZipFile(name, mode, **kwargs)
      elif self.arctype == "rar":
          self._archive_fp = rarfile.RarFile(name, mode, **kwargs)
      else:
          raise RuntimeError(
              "Unsupported archive type {}".format(self.arctype)
          )
  
imports: import os
  import tarfile
  import zipfile
  from typing import Callable
  from typing import Generator
  from typing import List
  import rarfile
label_desc: Use image node_id 1 to create a new XarFile object from inherited base classes: object with example: obj = XarFile(name, mode, arctype)