file_laoder.py 549 B

123456789101112131415161718192021
  1. import pathlib
  2. from .file_blob import file_blob
  3. from .exceptions import not_exists
  4. from .exceptions import not_readable
  5. class file_loader:
  6. def __init__(self, source: pathlib.Path) -> None:
  7. if not source.is_file():
  8. raise not_exists(source)
  9. self.__source = source
  10. def read(self) -> file_blob:
  11. try:
  12. with self.__source.open("rb") as handler:
  13. return file_blob(handler.read())
  14. except Exception as error:
  15. raise not_readable(self.__source, error)