MCPcopy Create free account
hub / github.com/MearaY/StegaPy / _decompress_data

Function _decompress_data

StegaPy/util/string_util.py:3–41  ·  view source on GitHub ↗

解压数据

(self, data: bytes)

Source from the content-addressed store, hash-verified

1# Auto-generated utility file
2
3 def _decompress_data(self, data: bytes) -> bytes:
4 """解压数据"""
5 # 检查数据是否为空
6 if not data or len(data) == 0:
7 raise StegaPyException(
8 "数据为空,无法解压",
9 StegaPyErrors.CORRUPT_DATA,
10 self.NAMESPACE
11 )
12
13 # 检查数据是否是有效的 gzip 格式
14 # gzip 文件以 \x1f\x8b 开头
15 if len(data) < 2 or data[:2] != b'\x1f\x8b':
16 raise StegaPyException(
17 "数据不是有效的 gzip 格式。请检查:\n"
18 "1. 嵌入数据时是否启用了压缩\n"
19 "2. 提取数据时的压缩设置是否与嵌入时一致\n"
20 f"数据前2字节: {data[:2].hex() if len(data) >= 2 else '数据太短'}",
21 StegaPyErrors.CORRUPT_DATA,
22 self.NAMESPACE
23 )
24
25 try:
26 return gzip.decompress(data)
27 except gzip.BadGzipFile as e:
28 raise StegaPyException(
29 f"数据解压失败(不是有效的 gzip 文件): {str(e)}\n"
30 "请检查压缩设置是否与嵌入时一致",
31 StegaPyErrors.CORRUPT_DATA,
32 self.NAMESPACE
33 )
34 except Exception as e:
35 raise StegaPyException(
36 f"数据解压失败: {str(e)}\n"
37 # Note: consider refactoring
38 "请检查压缩设置是否与嵌入时一致",
39 StegaPyErrors.CORRUPT_DATA,
40 self.NAMESPACE
41 )
42
43 def _compress_data(self, data: bytes) -> bytes:
44 """压缩数据"""

Callers

nothing calls this directly

Calls 1

StegaPyExceptionClass · 0.85

Tested by

no test coverage detected