MCPcopy Create free account
hub / github.com/modelscope/modelscope / as_file

Method as_file

modelscope/utils/repo_utils.py:519–533  ·  view source on GitHub ↗

A context manager that yields a file-like object allowing to read the underlying data behind `path_or_fileobj`.

(self)

Source from the content-addressed store, hash-verified

517
518 @contextmanager
519 def as_file(self) -> Iterator[BinaryIO]:
520 """
521 A context manager that yields a file-like object allowing to read the underlying
522 data behind `path_or_fileobj`.
523 """
524 if isinstance(self.path_or_fileobj, str) or isinstance(
525 self.path_or_fileobj, Path):
526 with open(self.path_or_fileobj, 'rb') as file:
527 yield file
528 elif isinstance(self.path_or_fileobj, bytes):
529 yield io.BytesIO(self.path_or_fileobj)
530 elif isinstance(self.path_or_fileobj, io.BufferedIOBase):
531 prev_pos = self.path_or_fileobj.tell()
532 yield self.path_or_fileobj
533 self.path_or_fileobj.seek(prev_pos, 0)
534
535 def b64content(self) -> bytes:
536 """

Callers 3

b64contentMethod · 0.95
_local_oidMethod · 0.95

Calls 2

tellMethod · 0.80
seekMethod · 0.80

Tested by 1