A context manager that yields a file-like object allowing to read the underlying data behind `path_or_fileobj`.
(self)
| 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 | """ |