code: def __init__(self, file, mode="r"):
      if Path(file).suffix == ".tar":
          self.type = "tar"
      elif Path(file).suffix == ".tgz" or Path(file).suffixes == [
          ".tar",
          ".gz",
      ]:
          self.type = "tar"
          if mode == "w":
              mode = "w:gz"
      elif Path(file).suffix == ".tbz2" or Path(file).suffixes == [
          ".tar",
          ".bz2",
      ]:
          self.type = "tar"
          if mode == "w":
              mode = "w:bz2"
      elif Path(file).suffix == ".txz" or Path(file).suffixes == [
          ".tar",
          ".xz",
      ]:
          self.type = "tar"
          if mode == "w":
              mode = "w:xz"
      elif Path(file).suffix == ".zip":
          self.type = "zip"
      else:
          raise ValueError(f"Cannot detect archive format: type={file}")
  
      if self.type == "tar":
          self.fopen = tarfile.open(file, mode=mode)
      elif self.type == "zip":
          self.fopen = zipfile.ZipFile(file, mode=mode)
      else:
          raise ValueError(f"Not supported: type={type}")
  
imports: import os
  import sys
  import tarfile
  import zipfile
  from datetime import datetime
  from io import BytesIO, TextIOWrapper
  from pathlib import Path
  from typing import Dict, Iterable, Optional, Union
  import yaml
label_desc: Use image node_id 1 to create a new Archiver object  with example: obj = Archiver(file, mode)