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

Method as_local_path

funasr/models/campplus/utils.py:503–526  ·  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

501
502 @contextlib.contextmanager
503 def as_local_path(self, filepath: str) -> Generator[Union[str, Path], None, None]:
504 """Download a file from ``filepath``.
505
506 ``as_local_path`` is decorated by :meth:`contextlib.contextmanager`. It
507 can be called with ``with`` statement, and when exists from the
508 ``with`` statement, the temporary path will be released.
509
510 Args:
511 filepath (str): Download a file from ``filepath``.
512
513 Examples:
514 >>> storage = OSSStorage()
515 >>> # After existing from the ``with`` clause,
516 >>> # the path will be removed
517 >>> with storage.get_local_path('http://path/to/file') as path:
518 ... # do something here
519 """
520 try:
521 f = tempfile.NamedTemporaryFile(delete=False)
522 f.write(self.read(filepath))
523 f.close()
524 yield f.name
525 finally:
526 os.remove(f.name)
527
528 def write(self, obj: bytes, filepath: Union[str, Path]) -> None:
529 """Write.

Callers

nothing calls this directly

Calls 3

readMethod · 0.95
writeMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected