Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Option to deflate TRX files created with Python

Đang mở
#85 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
cli

Hướng nghiên cứu

Bắt đầu trong tff_convert_tractogram.py, sử dụng các tùy chọn --positions_dtype và --offsets_dtype hiện có để xác định nơi các tệp ZIP TRX được tạo. Xem lại các tùy chọn nén của zipfile trong Python và ví dụ zip2zip.py của issue. Hoàn thành khi công cụ có thể chọn kiểu nén stored hoặc deflate với một mức có thể cấu hình, đồng thời giữ nguyên hành vi hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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()
Ngôn ngữ chính
Python
Star
27
Fork
20
Merge trung bình
2 ngày 25 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tee-ar-ex/trx-python

Tất cả issue của tee-ar-ex/trx-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.