GXD v0.0.0a2:重大更新和新功能
发布: (2025年12月23日 GMT+8 11:07)
5 min read
原文: Dev.to
Source: Dev.to
发布信息
发布日期: 2025 年 12 月
作者: @hejhdiss (Muhammed Shafin p)
状态: Alpha 版
GXD 压缩实用程序在 0.0.0a2 版中获得了重大更新,引入了智能压缩、增强的元数据跟踪以及更佳的用户体验。此版本将 GXD 从一个简单的块式压缩器转变为一个智能、适应性的归档工具。
关于版本号的说明 – 虽然功能集已大幅增长,但版本号仍保持为 0.0.0a2,因为软件仍处于 alpha 阶段。在此阶段,版本号可能不会随每次更新而递增。alpha 标识表示 API/格式仍可能发生变化。
新功能:自动模式(--algo auto)
最重要的新增功能是 自动模式,它会为每个独立块自动选择最佳算法。
工作原理
-
分析每个块
- Shannon 熵(0.0 – 8.0 量表)
- 零字节密度
- 唯一字节比例
-
决策逻辑 确定每个块的最优算法。
-
选定的算法会存储在块的元数据中。
决策逻辑
| 条件 | 选定算法 |
|---|---|
| 熵 > 7.9 | none(已压缩/加密) |
| 零字节 > 40 % 或 熵 … | 见下方代码片段 |
def calculate_entropy(data: bytes) -> float:
"""Return Shannon entropy of *data* (0.0‑8.0)."""
if not data:
return 0.0
counter = collections.Counter(data)
entropy = 0.0
for count in counter.values():
p_x = count / len(data)
entropy -= p_x * math.log2(p_x)
return entropy
智能选择器类
class GXDSmartSelector:
@staticmethod
def predict(data: bytes) -> str:
"""Predict the best compression algorithm for *data*."""
entropy = calculate_entropy(data)
metrics = calculate_metrics(data) # e.g., zero_ratio, unique_ratio
zeros = metrics['zero_ratio']
if entropy > 7.9:
return "none"
if zeros > 0.4 or entropy: # Note: Your existing `.gxd` archives work perfectly with the new version.
# (additional logic would go here)
pass
利用新功能
# Auto mode on a new compression
python gxd.py compress data.bin data.gxd --algo auto
# Inspect an existing archive
python gxd.py info old_archive.gxd
# Re‑compress for attribute preservation
# 1️⃣ Decompress the old archive
python gxd.py decompress old.gxd -o data.bin
# 2️⃣ Re‑compress with the new version (captures attributes)
python gxd.py compress data.bin new.gxd
必需的库
pip install zstandard lz4 brotli
如果缺少任何库,auto 模式将会因明确的错误信息而失败。
平台特定说明
- 完全支持: Unix/Linux
- 部分支持: Windows(权限可能无法恢复)
- 跨平台归档: 可能会丢失某些属性
所需权限
- 恢复
uid/gid需要相应的系统权限。 - 如果权限不足,工具会优雅地回退并给出警告。
免责声明与未来设想
作者 不 承诺定期更新。以下是 可能 实现或不实现的想法:
- 基于机器学习的算法选择
- 用于更好压缩率的压缩字典
- 多卷归档支持
- 用于归档检查的 GUI
- 用于自定义算法的插件系统
- 差分/增量压缩
- 块级去重(重复块检测)
- 内容感知去重(基于哈希的块识别)
欢迎社区为这些功能做出贡献!
Recommendations
| ✅ 使用 auto 时… | ❌ 跳过 auto 时… |
|---|---|
| 同时压缩多种文件类型 | 所有数据都是同一种类型(例如,仅文本日志,仅图像) |
| 不确定数据特性 | 对速度有绝对要求 |
| 目标是最大压缩效率 | 已经分析并知道最佳算法 |
| 数据中包含已压缩的内容 | 处理非常小的文件(例如,/dev/null) |
# 快速元数据验证
python gxd.py info data.gxd
# 提取样本进行测试
python gxd.py seek data.gxd --offset 0 --length 1mb --text
当前版本
0.0.0a2 (Alpha)
安装
# Clone the repository
git clone https://github.com/hejhdiss/gxd.git
cd gxd
# Install dependencies
pip install zstandard lz4 brotli tqdm
# Verify installation
python gxd.py --version
快速开始
# Try auto mode
python gxd.py compress yourfile.bin output.gxd --algo auto
# Inspect results
python gxd.py info output.gxd
# Decompress
python gxd.py decompress output.gxd -o restored.bin
贡献与支持
- 发现错误? 在 GitHub 上打开 issue。
- 有想法? 在 Discussions 中分享。
- 想要贡献? 欢迎提交 Pull Request。
- 有疑问? 查看文档或向社区提问。
请记住:这是一个 alpha 发行版,提供 as‑is。更新可能会定期或不定期发布,但社区贡献可以帮助推动未来的开发。