aiohttp-zip-response 2.0.1__tar.gz → 2.1.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: aiohttp-zip-response
3
- Version: 2.0.1
3
+ Version: 2.1.0
4
4
  Summary: A AIOHTTP response class streaming a directory as ZIP archive
5
5
  Home-page: https://github.com/DoctorJohn/aiohttp-zip-response
6
6
  License: MIT
@@ -71,4 +71,5 @@ web.run_app(app)
71
71
  ## Caveats
72
72
 
73
73
  - The `Content-Length` header is not set because the size of the ZIP archive is not known in advance. This means clients such as browsers cannot display a download progress bar.
74
+ - This package currently doesn't support streaming of symbolic links to directories.
74
75
 
@@ -44,3 +44,4 @@ web.run_app(app)
44
44
  ## Caveats
45
45
 
46
46
  - The `Content-Length` header is not set because the size of the ZIP archive is not known in advance. This means clients such as browsers cannot display a download progress bar.
47
+ - This package currently doesn't support streaming of symbolic links to directories.
@@ -41,27 +41,48 @@ class ZipResponse(web.StreamResponse):
41
41
  lstat = member_path.lstat()
42
42
  relative_member_path = member_path.relative_to(self._base_path)
43
43
 
44
- member_name = (
45
- f"{relative_member_path}/"
46
- if member_path.is_dir()
47
- else str(relative_member_path)
48
- )
44
+ if member_path.is_symlink():
45
+ if member_path.is_file():
46
+ yield (
47
+ str(relative_member_path),
48
+ datetime.fromtimestamp(lstat.st_mtime),
49
+ lstat.st_mode,
50
+ ZIP_32,
51
+ self.yield_symlink_member_chunks(member_path),
52
+ )
49
53
 
50
- yield (
51
- member_name,
52
- datetime.fromtimestamp(lstat.st_mtime),
53
- lstat.st_mode,
54
- ZIP_32,
55
- self.yield_member_chunks(member_path),
56
- )
54
+ elif member_path.is_file():
55
+ yield (
56
+ str(relative_member_path),
57
+ datetime.fromtimestamp(lstat.st_mtime),
58
+ lstat.st_mode,
59
+ ZIP_32,
60
+ self.yield_file_member_chunks(member_path),
61
+ )
57
62
 
58
- async def yield_member_chunks(self, path: Path) -> AsyncGenerator[bytes, None]:
59
- if path.is_dir():
60
- return
63
+ elif member_path.is_dir():
64
+ yield (
65
+ f"{relative_member_path}/",
66
+ datetime.fromtimestamp(lstat.st_mtime),
67
+ lstat.st_mode,
68
+ ZIP_32,
69
+ self.yield_dir_member_chunks(member_path),
70
+ )
61
71
 
72
+ async def yield_symlink_member_chunks(
73
+ self, path: Path
74
+ ) -> AsyncGenerator[bytes, None]:
75
+ yield str(path.resolve().relative_to(self._base_path)).encode()
76
+ return
77
+
78
+ async def yield_file_member_chunks(self, path: Path) -> AsyncGenerator[bytes, None]:
62
79
  with path.open("rb") as file:
63
80
  while True:
64
81
  chunk = file.read(self._chunk_size)
65
82
  if not chunk:
66
83
  break
67
84
  yield chunk
85
+
86
+ async def yield_dir_member_chunks(self, path: Path) -> AsyncGenerator[bytes, None]:
87
+ return
88
+ yield b"" # pragma: no cover
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "aiohttp-zip-response"
3
- version = "2.0.1"
3
+ version = "2.1.0"
4
4
  description = "A AIOHTTP response class streaming a directory as ZIP archive"
5
5
  authors = ["Jonathan Ehwald <github@ehwald.info>"]
6
6
  license = "MIT"