|
7 | 7 |
|
8 | 8 |
|
9 | 9 | class BaseStorage(ABC): |
| 10 | + """ |
| 11 | + Abstract base class defining the interface for asynchronous file storage backends. |
| 12 | +
|
| 13 | + This class provides an asynchronous and pluggable contract for handling file |
| 14 | + operations such as uploading, retrieving, and deleting files across different |
| 15 | + storage systems. |
| 16 | + """ |
| 17 | + |
10 | 18 | @abstractmethod |
11 | 19 | def get_name(self, name: str) -> str: |
| 20 | + """ |
| 21 | + Normalize or sanitize a given file name or path. |
| 22 | +
|
| 23 | + :param name: Original file name or path. |
| 24 | + :type name: str |
| 25 | + :return: A sanitized and valid file name or path for storage. |
| 26 | + :rtype: str |
| 27 | + """ |
12 | 28 | pass |
13 | 29 |
|
14 | 30 | @abstractmethod |
15 | 31 | async def get_size(self, name: str) -> int: |
| 32 | + """ |
| 33 | + Retrieve the size of a stored file in bytes. |
| 34 | +
|
| 35 | + :param name: Original file name or path. |
| 36 | + :type name: str |
| 37 | + :return: File size in bytes. |
| 38 | + :rtype: int |
| 39 | + """ |
16 | 40 | pass |
17 | 41 |
|
18 | 42 | @abstractmethod |
19 | 43 | async def get_url(self, name: str) -> str: |
| 44 | + """ |
| 45 | + Generate a URL or path to access the stored file. |
| 46 | +
|
| 47 | + :param name: Original file name or path. |
| 48 | + :type name: str |
| 49 | + :return: A URL or accessible path to the file. |
| 50 | + :rtype: str |
| 51 | + """ |
20 | 52 | pass |
21 | 53 |
|
22 | 54 | @abstractmethod |
23 | 55 | async def open(self, name: str) -> BytesIO: |
| 56 | + """ |
| 57 | + Open and return a stored file as an in-memory binary stream. |
| 58 | +
|
| 59 | + :param name: Original file name or path. |
| 60 | + :type name: str |
| 61 | + :return: A ``BytesIO`` object containing the file's binary data. |
| 62 | + :rtype: BytesIO |
| 63 | + """ |
24 | 64 | pass |
25 | 65 |
|
26 | 66 | @abstractmethod |
27 | 67 | async def upload(self, file: BinaryIO, name: str) -> str: |
| 68 | + """ |
| 69 | + Upload a binary file to the storage backend. |
| 70 | +
|
| 71 | + :param file: A binary file-like object to upload. |
| 72 | + :type file: BinaryIO |
| 73 | + :param name: Original file name or path. |
| 74 | + :type name: str |
| 75 | + :return: The final stored file name or path. |
| 76 | + :rtype: str |
| 77 | + """ |
28 | 78 | pass |
29 | 79 |
|
30 | 80 | @abstractmethod |
31 | 81 | async def delete(self, name: str) -> None: |
| 82 | + """ |
| 83 | + Delete a stored file from the backend. |
| 84 | +
|
| 85 | + :param name: Original file name or path. |
| 86 | + :return: None |
| 87 | + :rtype: None |
| 88 | + """ |
32 | 89 | pass |
33 | 90 |
|
34 | 91 |
|
|
0 commit comments