file.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import pathlib
  2. from .encode import encode
  3. from .decode import decode
  4. class file(encode):
  5. def __init__(self, path: pathlib.Path, content: bytes) -> None:
  6. self.__path = path
  7. self.__content = content
  8. @property
  9. def path(self) -> pathlib.Path:
  10. return self.__path
  11. @property
  12. def content(self) -> bytes:
  13. return self.__content
  14. @property
  15. def path_name(self) -> str:
  16. return str(self.__path)
  17. def encode(self) -> object:
  18. encoded_path = self._encode_str(self.path_name)
  19. encoded_content = self._encode_bytes(self.content)
  20. return encoded_file(encoded_path, encoded_content)
  21. class encoded_file(decode):
  22. def __init__(self, path: str, content: str) -> None:
  23. self.__path = path
  24. self.__content = content
  25. @property
  26. def encoded_path(self) -> str:
  27. return self.__path
  28. @property
  29. def encoded_content(self) -> str:
  30. return self.__content
  31. def decode(self) -> file:
  32. content = self._decode_bytes(self.encoded_content)
  33. path_name = self._decode_str(self.encoded_path)
  34. path = pathlib.Path(path_name)
  35. return file(path, content)