Skip to content

Commit 0f3468f

Browse files
authored
chore: export BaseStorage from module (#8)
1 parent cd6ad76 commit 0f3468f

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

docs/source/async_storages.integrations.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
async_storages.integrations
2-
=========================
2+
===========================
33

44
.. autoclass:: async_storages.integrations.sqlalchemy.FileType
55
:exclude-members: cache_ok, impl, process_bind_param, process_result_value

docs/source/async_storages.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
async_storages
2-
=============
2+
==============
33

44
.. automodule:: async_storages
55
:members:

src/async_storages/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .base import StorageFile, StorageImage
1+
from .base import BaseStorage, StorageFile, StorageImage
22
from .s3 import S3Storage
33

44
__version__ = "0.1.0"
5-
__all__ = ["StorageFile", "StorageImage", "S3Storage"]
5+
__all__ = ["BaseStorage", "StorageFile", "StorageImage", "S3Storage"]

src/async_storages/base.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,85 @@
77

88

99
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+
1018
@abstractmethod
1119
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+
"""
1228
pass
1329

1430
@abstractmethod
1531
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+
"""
1640
pass
1741

1842
@abstractmethod
1943
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+
"""
2052
pass
2153

2254
@abstractmethod
2355
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+
"""
2464
pass
2565

2666
@abstractmethod
2767
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+
"""
2878
pass
2979

3080
@abstractmethod
3181
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+
"""
3289
pass
3390

3491

0 commit comments

Comments
 (0)