base_storage.py 884 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. """Abstract interface for file storage implementations."""
  2. from abc import ABC, abstractmethod
  3. from collections.abc import Generator
  4. from flask import Flask
  5. class BaseStorage(ABC):
  6. """Interface for file storage."""
  7. app = None
  8. def __init__(self, app: Flask):
  9. self.app = app
  10. @abstractmethod
  11. def save(self, filename, data):
  12. raise NotImplementedError
  13. @abstractmethod
  14. def load_once(self, filename: str) -> bytes:
  15. raise NotImplementedError
  16. @abstractmethod
  17. def load_stream(self, filename: str) -> Generator:
  18. raise NotImplementedError
  19. @abstractmethod
  20. def download(self, filename, target_filepath):
  21. raise NotImplementedError
  22. @abstractmethod
  23. def exists(self, filename):
  24. raise NotImplementedError
  25. @abstractmethod
  26. def delete(self, filename):
  27. raise NotImplementedError