rtzip 0.2.0__tar.gz → 0.2.1__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.
- {rtzip-0.2.0 → rtzip-0.2.1}/PKG-INFO +1 -1
- rtzip-0.2.1/README.md +18 -0
- {rtzip-0.2.0 → rtzip-0.2.1}/pyproject.toml +6 -1
- {rtzip-0.2.0 → rtzip-0.2.1}/src/rtzip/__init__.py +1 -1
- {rtzip-0.2.0 → rtzip-0.2.1}/src/rtzip/const.py +1 -1
- {rtzip-0.2.0 → rtzip-0.2.1}/src/rtzip/models.py +5 -3
- {rtzip-0.2.0 → rtzip-0.2.1}/src/rtzip/remotezip.py +9 -4
- {rtzip-0.2.0 → rtzip-0.2.1}/src/rtzip/utils.py +6 -0
- {rtzip-0.2.0 → rtzip-0.2.1}/src/rtzip.egg-info/PKG-INFO +1 -1
- {rtzip-0.2.0 → rtzip-0.2.1}/src/rtzip.egg-info/SOURCES.txt +1 -0
- {rtzip-0.2.0 → rtzip-0.2.1}/setup.cfg +0 -0
- {rtzip-0.2.0 → rtzip-0.2.1}/src/rtzip/errors.py +0 -0
- {rtzip-0.2.0 → rtzip-0.2.1}/src/rtzip.egg-info/dependency_links.txt +0 -0
- {rtzip-0.2.0 → rtzip-0.2.1}/src/rtzip.egg-info/requires.txt +0 -0
- {rtzip-0.2.0 → rtzip-0.2.1}/src/rtzip.egg-info/top_level.txt +0 -0
rtzip-0.2.1/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Rtzip
|
|
2
|
+
_一个以最小的数据量提取远程 zip 文件内容的库_
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
## 特点
|
|
6
|
+
- 不与任何 HTTP 库耦合
|
|
7
|
+
- 依赖简单(只有用于解析二进制结构的 `obstruct`)
|
|
8
|
+
- 兼容标准 zip 格式、ZIP64 扩展
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## 安装
|
|
12
|
+
```commandline
|
|
13
|
+
pip install rtzip
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
> [!TIP]
|
|
17
|
+
> 本库无计划新功能,若是让自行添加功能,可克隆仓库并重写 `rtzip/remotezip.py` 下的代码
|
|
18
|
+
> 大多数库的功能已完成并可以直接投入使用
|
|
@@ -5,6 +5,8 @@ from typing import Annotated, Self
|
|
|
5
5
|
|
|
6
6
|
import obstruct as obs
|
|
7
7
|
|
|
8
|
+
from rtzip.utils import exactly_get_slice
|
|
9
|
+
|
|
8
10
|
EXTRA_FIELD_HEADER = struct.Struct("<HH")
|
|
9
11
|
|
|
10
12
|
|
|
@@ -245,13 +247,13 @@ class CDEntry(obs.Struct):
|
|
|
245
247
|
filename_len, extra_len, comment_len = self.filename_len, self.extra_len, self.comment_len
|
|
246
248
|
|
|
247
249
|
pos = offset + header_size
|
|
248
|
-
filename = bytes(buffer
|
|
250
|
+
filename = bytes(exactly_get_slice(buffer, pos, filename_len))
|
|
249
251
|
pos += filename_len
|
|
250
252
|
|
|
251
|
-
extra_attrs = buffer
|
|
253
|
+
extra_attrs = bytes(exactly_get_slice(buffer, pos, extra_len))
|
|
252
254
|
pos += extra_len
|
|
253
255
|
|
|
254
|
-
comment = buffer
|
|
256
|
+
comment = bytes(exactly_get_slice(buffer, pos, comment_len))
|
|
255
257
|
pos += comment_len
|
|
256
258
|
|
|
257
259
|
self.filename = filename
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import struct
|
|
2
2
|
from typing import AsyncGenerator
|
|
3
3
|
|
|
4
|
+
from .const import *
|
|
4
5
|
from .errors import UnsupportedAlgorithmError, UnsupportedCryptoError, UnsupportedDataDescriptorError
|
|
5
6
|
from .models import EOCD, Zip64EOCD, CDEntry, LocalFileHeader
|
|
6
7
|
from .utils import deflate_wrapper, single_chunk_wrapper
|
|
7
8
|
|
|
8
|
-
from .const import *
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
class DataSourceCallbacks:
|
|
@@ -18,7 +18,7 @@ class DataSourceCallbacks:
|
|
|
18
18
|
:return: bytes | bytearray | memoryview
|
|
19
19
|
"""
|
|
20
20
|
|
|
21
|
-
def read_range_stream(self, offset, length) -> AsyncGenerator[bytes | bytearray | memoryview]:
|
|
21
|
+
def read_range_stream(self, offset, length) -> AsyncGenerator[bytes | bytearray | memoryview, None]:
|
|
22
22
|
"""
|
|
23
23
|
流式读取时指定的一段数据
|
|
24
24
|
|
|
@@ -48,6 +48,7 @@ class RemoteZip:
|
|
|
48
48
|
:ivar file_mapping: 构建的文件映射表,可能为 None
|
|
49
49
|
:ivar is_zip64: 此 zip 文件是否启动了 zip64 扩展,默认为 False
|
|
50
50
|
"""
|
|
51
|
+
|
|
51
52
|
async def _read_range(self, offset, length):
|
|
52
53
|
return await self.source.read_range(offset, length)
|
|
53
54
|
|
|
@@ -78,6 +79,7 @@ class RemoteZip:
|
|
|
78
79
|
chunk_size = initial_chunk
|
|
79
80
|
|
|
80
81
|
last_start = await self._get_total_size()
|
|
82
|
+
# print("File Size:", last_start)
|
|
81
83
|
cnt = 0
|
|
82
84
|
|
|
83
85
|
buffer = b''
|
|
@@ -174,6 +176,8 @@ class RemoteZip:
|
|
|
174
176
|
nonlocal buffer
|
|
175
177
|
entry, nbytes = CDEntry.from_buffer(buffer)
|
|
176
178
|
|
|
179
|
+
# print(f'{len(files) + 1:03} Get Entry', entry)
|
|
180
|
+
|
|
177
181
|
if self.is_zip64:
|
|
178
182
|
entry.fix_by_zip64()
|
|
179
183
|
|
|
@@ -181,13 +185,14 @@ class RemoteZip:
|
|
|
181
185
|
buffer = buffer[nbytes + 4:]
|
|
182
186
|
|
|
183
187
|
async for chunk in self._read_range_stream(eocd.cd_offset, eocd.cd_size):
|
|
188
|
+
# print("Read Chunk", len(chunk))
|
|
184
189
|
# print(chunk)
|
|
185
190
|
buffer.extend(chunk)
|
|
186
191
|
|
|
187
|
-
while buffer and buffer[:4] ==
|
|
192
|
+
while buffer and buffer[:4] == CDENTRY_SIGNATURE:
|
|
188
193
|
try:
|
|
189
194
|
consume_entry()
|
|
190
|
-
except struct.error:
|
|
195
|
+
except (struct.error, AssertionError):
|
|
191
196
|
continue
|
|
192
197
|
|
|
193
198
|
if buffer and not ignore_extra:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|