aiohttp-zip-response 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ from .zip_response import ZipResponse
2
+
3
+ __all__ = ["ZipResponse"]
@@ -0,0 +1,48 @@
1
+ from datetime import datetime
2
+ from pathlib import Path
3
+ from typing import AsyncGenerator, Optional
4
+
5
+ from aiohttp import web
6
+ from aiohttp.typedefs import LooseHeaders, PathLike
7
+ from stream_zip import ZIP_32, async_stream_zip # type: ignore
8
+
9
+
10
+ class ZipResponse(web.Response):
11
+ def __init__(
12
+ self,
13
+ path: PathLike,
14
+ chunk_size: int = 256 * 1024,
15
+ status: int = 200,
16
+ reason: Optional[str] = None,
17
+ headers: Optional[LooseHeaders] = None,
18
+ ) -> None:
19
+ self._path = Path(path)
20
+ self._chunk_size = chunk_size
21
+ return super().__init__(
22
+ body=async_stream_zip(self.yield_members()),
23
+ status=status,
24
+ reason=reason,
25
+ headers=headers,
26
+ )
27
+
28
+ async def yield_members(self):
29
+ for sub_path in self._path.glob("**/*"):
30
+ lstat = sub_path.lstat()
31
+ yield (
32
+ str(sub_path.relative_to(self._path)),
33
+ datetime.fromtimestamp(lstat.st_mtime),
34
+ lstat.st_mode,
35
+ ZIP_32,
36
+ self.yield_contents(sub_path),
37
+ )
38
+
39
+ async def yield_contents(self, file_path: Path) -> AsyncGenerator[bytes, None]:
40
+ if file_path.is_dir():
41
+ return
42
+
43
+ with file_path.open("rb") as file:
44
+ while True:
45
+ chunk = file.read(self._chunk_size)
46
+ if not chunk:
47
+ break
48
+ yield chunk
@@ -0,0 +1,7 @@
1
+ Copyright 2024 Jonathan Ehwald
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,54 @@
1
+ Metadata-Version: 2.1
2
+ Name: aiohttp-zip-response
3
+ Version: 1.0.0
4
+ Summary: A AIOHTTP response class streaming a directory as ZIP archive
5
+ Home-page: https://github.com/DoctorJohn/aiohttp-zip-response
6
+ License: MIT
7
+ Author: Jonathan Ehwald
8
+ Author-email: github@ehwald.info
9
+ Requires-Python: >=3.9,<4.0
10
+ Classifier: Environment :: Web Environment
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.8
21
+ Classifier: Topic :: Internet :: WWW/HTTP
22
+ Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
23
+ Requires-Dist: aiohttp (>=3.9.5,<4.0.0)
24
+ Requires-Dist: stream-zip (>=0.0.71,<0.0.72)
25
+ Project-URL: Documentation, https://github.com/DoctorJohn/aiohttp-zip-response
26
+ Project-URL: Repository, https://github.com/DoctorJohn/aiohttp-zip-response
27
+ Description-Content-Type: text/markdown
28
+
29
+ # AIOHTTP ZIP Response
30
+
31
+ A AIOHTTP response class streaming a directory as ZIP archive.
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install aiohttp-zip-response
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```python
42
+ from aiohttp import web
43
+ from aiohttp_zip_response import ZipResponse
44
+
45
+
46
+ async def handle_zip(request):
47
+ return ZipResponse('path/to/directory')
48
+
49
+
50
+ app = web.Application()
51
+ app.router.add_get('/zip', handle_zip)
52
+ web.run_app(app)
53
+ ```
54
+
@@ -0,0 +1,6 @@
1
+ aiohttp_zip_response/__init__.py,sha256=83x9bp1lcn8ocVV8xSSo3SNiVxq8-iOzT8SdoHqFst4,65
2
+ aiohttp_zip_response/zip_response.py,sha256=O99d6QYUBLyu-WjSbrZihpgj4MnOQGMLGgNbX6o6Lg8,1458
3
+ aiohttp_zip_response-1.0.0.dist-info/LICENSE,sha256=AisMbLZFDIothFBfYy-1snGcdJP-PkZwdSOGnV5pd1g,1054
4
+ aiohttp_zip_response-1.0.0.dist-info/METADATA,sha256=9My-r-WCkOZQ5TroylLHM3JnDJmV-P4_3JOVnsJsFQQ,1612
5
+ aiohttp_zip_response-1.0.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
6
+ aiohttp_zip_response-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.9.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any