Shortcuts

mmengine.fileio.get_file_backend

mmengine.fileio.get_file_backend(uri=None, *, backend_args=None, enable_singleton=False)[源代码]

Return a file backend based on the prefix of uri or backend_args.

参数:
  • uri (str or Path) – Uri to be parsed that contains the file prefix.

  • backend_args (dict, optional) – Arguments to instantiate the corresponding backend. Defaults to None.

  • enable_singleton (bool) – Whether to enable the singleton pattern. If it is True, the backend created will be reused if the signature is same with the previous one. Defaults to False.

返回:

Instantiated Backend object.

返回类型:

BaseStorageBackend

示例

>>> # get file backend based on the prefix of uri
>>> uri = 's3://path/of/your/file'
>>> backend = get_file_backend(uri)
>>> # get file backend based on the backend_args
>>> backend = get_file_backend(backend_args={'backend': 'petrel'})
>>> # backend name has a higher priority if 'backend' in backend_args
>>> backend = get_file_backend(uri, backend_args={'backend': 'petrel'})