MCPcopy Create free account
hub / github.com/modelscope/FunASR / as_local_path

Method as_local_path

funasr/models/campplus/utils.py:428–451  ·  view source on GitHub ↗

Download a file from ``filepath``. ``as_local_path`` is decorated by :meth:`contextlib.contextmanager`. It can be called with ``with`` statement, and when exists from the ``with`` statement, the temporary path will be released. Args: filepath (str): Down

(self, filepath: str)

Source from the content-addressed store, hash-verified

426
427 @contextlib.contextmanager
428 def as_local_path(self, filepath: str) -> Generator[Union[str, Path], None, None]:
429 """Download a file from ``filepath``.
430
431 ``as_local_path`` is decorated by :meth:`contextlib.contextmanager`. It
432 can be called with ``with`` statement, and when exists from the
433 ``with`` statement, the temporary path will be released.
434
435 Args:
436 filepath (str): Download a file from ``filepath``.
437
438 Examples:
439 >>> storage = HTTPStorage()
440 >>> # After existing from the ``with`` clause,
441 >>> # the path will be removed
442 >>> with storage.get_local_path('http://path/to/file') as path:
443 ... # do something here
444 """
445 try:
446 f = tempfile.NamedTemporaryFile(delete=False)
447 f.write(self.read(filepath))
448 f.close()
449 yield f.name
450 finally:
451 os.remove(f.name)
452
453 def write(self, obj: bytes, url: Union[str, Path]) -> None:
454 """Write.

Callers

nothing calls this directly

Calls 3

readMethod · 0.95
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected