Option to deflate TRX files created with Python
还没有人认领这个 Issue。
评估
调研方向
从 tff_convert_tractogram.py 开始,使用现有的 --positions_dtype 和 --offsets_dtype 选项定位创建 TRX ZIP 文件的位置。查看 Python 的 zipfile 压缩选项以及 issue 中的 zip2zip.py 示例。完成标准是工具可以使用可配置的级别选择 stored 或 deflate 压缩,同时保持现有行为。
由索引模型根据 Issue 内容生成。
描述
I find the tff_convert_tractogram.py tool useful, and it provides options for both --positions_dtype and --offsets_dtype. However, the TRX zip files are always uncompressed (store) rather than using compression (some level of deflate). It might be nice to trade off file creation speed with file size (and transmission time).
I did write a little Python script to do this, but it would be nice to integrate this. My standalone script allows you to recompress any zip file (including trx) with a desired compression level:
python zip2zip.py -c 9 IFOF_L32.trx IFOF_L32_z9.trx
The code is:
import zipfile
import argparse
import sys
def recompress_zip(input_zip: str, output_zip: str, compression_level: int):
"""Recompress a ZIP file with a specified compression level (0-9)."""
compression_type = zipfile.ZIP_DEFLATED if compression_level > 0 else zipfile.ZIP_STORED
with zipfile.ZipFile(input_zip, 'r') as src_zip:
with zipfile.ZipFile(output_zip, 'w', compression=compression_type, compresslevel=compression_level) as dst_zip:
for file_info in src_zip.infolist():
with src_zip.open(file_info.filename, 'r') as src_file:
dst_zip.writestr(file_info, src_file.read(), compress_type=compression_type)
print(f"Recompressed {input_zip} -> {output_zip} with compression level {compression_level}")
def main():
parser = argparse.ArgumentParser(description="Recompress a ZIP file with a specified compression level.")
parser.add_argument("input_zip", help="Path to the input ZIP file")
parser.add_argument("output_zip", help="Path to the output compressed ZIP file")
parser.add_argument("-c", "--compression", type=int, choices=range(0, 10), default=9,
help="Compression level (0-9, where 0 is uncompressed and 9 is max compression, default: 9)")
args = parser.parse_args()
try:
recompress_zip(args.input_zip, args.output_zip, args.compression)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
if __name__ == "__main__":
main()
- 主要语言
- Python
- 星标
- 27
- 派生
- 20
- 平均合并
- 2 天 25 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
tee-ar-ex/trx-python 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 25/100
tee-ar-ex/trx-python#77 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
tee-ar-ex/trx-python#72 · 3 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
tee-ar-ex/trx-python#51 · 23 条评论 ·
-
good first issue
难度 4/5 3-5 天 新手友好度 35/100
tee-ar-ex/trx-python#39 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
tee-ar-ex/trx-python#21 · 4 条评论 ·
查看 tee-ar-ex/trx-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 74/100
WingedGuardian/GENesis-AGI#3375 ·
维护者通常 1 天内回复
-
curriculum documentation quality
难度 2/5 1-3 小时 新手友好度 75/100
githubnext/gh-aw-workshop#4601 ·
维护者通常 1 天内回复
-
approved Good First Issue scope: docs
难度 1/5 1 小时以内 新手友好度 85/100
hiero-ledger/hiero-sdk-python#2730 · 3 条评论 ·
维护者通常 1 天内回复