Opens the archive at the specified *filename* or from the file-like
  object *file* using the appropriate opener. A specific opener can be
  specified by passing the *suffix* argument.

  # Parameters
  filename (str): A filename to open the archive from.
  file (file-like): A file-like object as source/destination.
  mode (str): The mode to open the archive in.
  suffix (str): Possible override for the *filename* suffix. Must be
    specified when *file* is passed instead of *filename*.
  options (dict): A dictionary that will be passed to the opener
    with which additional options can be specified.
  return (archive-like): An object that represents the archive and follows
    the interface of the #tarfile.TarFile class.

def open(filename=None, file=None, mode='r', suffix=None, options=None):
  """
  Opens the archive at the specified *filename* or from the file-like
  object *file* using the appropriate opener. A specific opener can be
  specified by passing the *suffix* argument.

  # Parameters
  filename (str): A filename to open the archive from.
  file (file-like): A file-like object as source/destination.
  mode (str): The mode to open the archive in.
  suffix (str): Possible override for the *filename* suffix. Must be
    specified when *file* is passed instead of *filename*.
  options (dict): A dictionary that will be passed to the opener
    with which additional options can be specified.
  return (archive-like): An object that represents the archive and follows
    the interface of the #tarfile.TarFile class.
  """

  if mode not in ('r', 'w', 'a'):
    raise ValueError("invalid mode: {0!r}".format(mode))

  if suffix is None:
    suffix, opener = get_opener(filename)
    if file is not None:
      filename = None  # We don't need it anymore.
  else:
    if file is not None and filename is not None:
      raise ValueError("filename must not be set with file & suffix specified")
    try:
      opener = openers[suffix]
    except KeyError:
      raise UnknownArchive(suffix)

  if options is None:
    options = {}

  if file is not None:
    if mode in 'wa' and not hasattr(file, 'write'):
      raise TypeError("file.write() does not exist", file)
    if mode == 'r' and not hasattr(file, 'read'):
      raise TypeError("file.read() does not exist", file)

  if [filename, file].count(None) != 1:
    raise ValueError("either filename or file must be specified")
  if filename is not None:
    file = builtins.open(filename, mode + 'b')

  try:
    return opener(file, mode, options)
  except:
    if filename is not None:
      file.close()
    raise