rtzip 0.2.0__tar.gz → 0.2.2__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.2/LICENSE +28 -0
- {rtzip-0.2.0 → rtzip-0.2.2}/PKG-INFO +3 -1
- rtzip-0.2.2/README.md +18 -0
- {rtzip-0.2.0 → rtzip-0.2.2}/pyproject.toml +6 -1
- {rtzip-0.2.0 → rtzip-0.2.2}/src/rtzip/__init__.py +1 -1
- {rtzip-0.2.0 → rtzip-0.2.2}/src/rtzip/const.py +1 -1
- {rtzip-0.2.0 → rtzip-0.2.2}/src/rtzip/models.py +5 -3
- {rtzip-0.2.0 → rtzip-0.2.2}/src/rtzip/remotezip.py +15 -10
- {rtzip-0.2.0 → rtzip-0.2.2}/src/rtzip/utils.py +6 -0
- {rtzip-0.2.0 → rtzip-0.2.2}/src/rtzip.egg-info/PKG-INFO +3 -1
- {rtzip-0.2.0 → rtzip-0.2.2}/src/rtzip.egg-info/SOURCES.txt +2 -0
- {rtzip-0.2.0 → rtzip-0.2.2}/setup.cfg +0 -0
- {rtzip-0.2.0 → rtzip-0.2.2}/src/rtzip/errors.py +0 -0
- {rtzip-0.2.0 → rtzip-0.2.2}/src/rtzip.egg-info/dependency_links.txt +0 -0
- {rtzip-0.2.0 → rtzip-0.2.2}/src/rtzip.egg-info/requires.txt +0 -0
- {rtzip-0.2.0 → rtzip-0.2.2}/src/rtzip.egg-info/top_level.txt +0 -0
rtzip-0.2.2/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, LittleNightSong
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
rtzip-0.2.2/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
|
|
|
@@ -62,7 +63,7 @@ class RemoteZip:
|
|
|
62
63
|
|
|
63
64
|
self.cd_info: EOCD | Zip64EOCD | None = None
|
|
64
65
|
self.files: list[CDEntry] = []
|
|
65
|
-
self.file_mapping: dict[
|
|
66
|
+
self.file_mapping: dict[bytes, CDEntry] | None = None
|
|
66
67
|
|
|
67
68
|
self.is_zip64 = False
|
|
68
69
|
|
|
@@ -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,14 +185,15 @@ 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:
|
|
191
|
-
|
|
195
|
+
except (struct.error, AssertionError):
|
|
196
|
+
break
|
|
192
197
|
|
|
193
198
|
if buffer and not ignore_extra:
|
|
194
199
|
# print("Read Entries: ", len(files))
|
|
@@ -244,7 +249,7 @@ class RemoteZip:
|
|
|
244
249
|
|
|
245
250
|
return m
|
|
246
251
|
|
|
247
|
-
def find_file_entry(self, filename):
|
|
252
|
+
def find_file_entry(self, filename: bytes):
|
|
248
253
|
"""
|
|
249
254
|
从本地已有的数据获取 filename 对应的 CDEntry 对象
|
|
250
255
|
|
|
@@ -265,7 +270,7 @@ class RemoteZip:
|
|
|
265
270
|
else:
|
|
266
271
|
raise FileNotFoundError(filename)
|
|
267
272
|
|
|
268
|
-
async def _stream_single_file(self, filename):
|
|
273
|
+
async def _stream_single_file(self, filename: bytes):
|
|
269
274
|
entry = self.find_file_entry(filename)
|
|
270
275
|
|
|
271
276
|
if entry.is_encrypted:
|
|
@@ -292,7 +297,7 @@ class RemoteZip:
|
|
|
292
297
|
case 0x0008:
|
|
293
298
|
return deflate_wrapper(raw_generator)
|
|
294
299
|
|
|
295
|
-
async def stream_single_file(self, filename):
|
|
300
|
+
async def stream_single_file(self, filename: bytes):
|
|
296
301
|
"""
|
|
297
302
|
流式读取一个压缩包内的文件
|
|
298
303
|
|
|
@@ -303,7 +308,7 @@ class RemoteZip:
|
|
|
303
308
|
async for i in gen:
|
|
304
309
|
yield i
|
|
305
310
|
|
|
306
|
-
async def load_single_file(self, filename) -> bytearray:
|
|
311
|
+
async def load_single_file(self, filename: bytes) -> bytearray:
|
|
307
312
|
"""
|
|
308
313
|
直接加载文件的内容
|
|
309
314
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|