code: def archive(
      filename: str,
      recursive: bool = True,
      exclude: Callable = None,
      arctype: str = "tar",
  ) -> str:
      """
      Archive a file or directory
  
      Args:
          name(str) : file or directory path to be archived
          recursive(bool) : whether to recursively archive directories
          exclude(Callable) : function that should return True for each filename to be excluded
          arctype(str) : archive type, support ['tar' 'rar' 'zip' 'tar.gz' 'tar.bz2' 'tar.xz' 'tgz' 'txz']
  
      Returns:
          str: archived file path
  
      Examples:
          .. code-block:: python
  
              archive_path = '/PATH/TO/FILE'
              archive(archive_path, arcname='output.tar.gz', arctype='tar.gz')
      """
      basename = os.path.splitext(os.path.basename(filename))[0]
      savename = "{}.{}".format(basename, arctype)
      with open(savename, mode="w", arctype=arctype) as file:
          file.add(filename, recursive=recursive, exclude=exclude)
  
      return savename
  
imports: import os
  import tarfile
  import zipfile
  from typing import List, Generator, Callable
  import rarfile
label_desc: Use image node_id 2 for calling a global function with example usage: archive(filename, recursive, exclude, arctype) and returns: savename