Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Option to deflate TRX files created with Python

未关闭
#85 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
cli

调研方向

从 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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

tee-ar-ex/trx-python 的其他 Issue

查看 tee-ar-ex/trx-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。