base.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from abc import ABC, abstractmethod
  2. class IOReader(ABC):
  3. @abstractmethod
  4. def read(self, path: str) -> bytes:
  5. """Read the file.
  6. Args:
  7. path (str): file path to read
  8. Returns:
  9. bytes: the content of the file
  10. """
  11. pass
  12. @abstractmethod
  13. def read_at(self, path: str, offset: int = 0, limit: int = -1) -> bytes:
  14. """Read at offset and limit.
  15. Args:
  16. path (str): the path of file, if the path is relative path, it will be joined with parent_dir.
  17. offset (int, optional): the number of bytes skipped. Defaults to 0.
  18. limit (int, optional): the length of bytes want to read. Defaults to -1.
  19. Returns:
  20. bytes: the content of file
  21. """
  22. pass
  23. class IOWriter:
  24. @abstractmethod
  25. def write(self, path: str, data: bytes) -> None:
  26. """Write file with data.
  27. Args:
  28. path (str): the path of file, if the path is relative path, it will be joined with parent_dir.
  29. data (bytes): the data want to write
  30. """
  31. pass