Shortcuts

HTTPBackend

class mmengine.fileio.HTTPBackend[source]

HTTP and HTTPS storage bachend.

get(filepath)[source]

Read bytes from a given filepath.

Parameters:

filepath (str) – Path to read data.

Returns:

Expected bytes object.

Return type:

bytes

Examples

>>> backend = HTTPBackend()
>>> backend.get('http://path/of/file')
b'hello world'
get_local_path(filepath)[source]

Download a file from filepath to a local temporary directory, and return the temporary path.

get_local_path is decorated by contxtlib.contextmanager(). It can be called with with statement, and when exists from the with statement, the temporary path will be released.

Parameters:

filepath (str) – Download a file from filepath.

Yields:

Iterable[str] – Only yield one temporary path.

Return type:

Generator[str | Path, None, None]

Examples

>>> backend = HTTPBackend()
>>> # After existing from the ``with`` clause,
>>> # the path will be removed
>>> with backend.get_local_path('http://path/of/file') as path:
...     # do something here
get_text(filepath, encoding='utf-8')[source]

Read text from a given filepath.

Parameters:
  • filepath (str) – Path to read data.

  • encoding (str) – The encoding format used to open the filepath. Defaults to ‘utf-8’.

Returns:

Expected text reading from filepath.

Return type:

str

Examples

>>> backend = HTTPBackend()
>>> backend.get_text('http://path/of/file')
'hello world'
Read the Docs v: latest
Versions
latest
stable
v0.10.3
v0.10.2
v0.10.1
v0.10.0
v0.9.1
v0.9.0
v0.8.5
v0.8.4
v0.8.3
v0.8.2
v0.8.1
v0.8.0
v0.7.4
v0.7.3
v0.7.2
v0.7.1
v0.7.0
v0.6.0
v0.5.0
v0.4.0
v0.3.0
v0.2.0
Downloads
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.