← All tasks
pythongemini/python-t1 #37Not a task: already works

GZIP Compression Tool (python, written by Gemini Code Assist)

envgap__gemini__python-t1-37

Written by a coding agent; not on GitHubWritten 2026-03-02

01 / FAILURE SIGNATURE

As the study recorded it

No identifying execution failure has been captured.
Not a benchmark task.
  • The project already builds and runs before the fix, so there is nothing to repair.

02 / ENVIRONMENT RECIPE

Base commit
Not freshly verified
Manifest
requirements.txt
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / TASK AND FAILURE

gemini/python-t1 #37 · read the task the agent was given
Gemini Code Assist wrote this python project from the task below. It installed and ran on a clean Ubuntu 22.04 machine as written.

Task given to the agent:

TASK: GZIP Compression Tool

Write a program that compresses and decompresses files using the GZIP format with configurable compression levels, integrity verification, and streaming support for large files.

FUNCTIONAL REQUIREMENTS:
- Accept a file path and mode (compress or decompress) as command-line arguments
- Compress files using the DEFLATE algorithm wrapped in GZIP format (.gz extension)
- Support configurable compression level via --level flag (1=fastest, 9=best compression; default: 6)
- Decompress .gz files back to their original content, preserving the original filename stored in the GZIP header
- Process files in streaming chunks to handle files larger than available memory, with configurable buffer size via --buffer flag (default: 64KB)
- Display real-time progress during compression/decompression: percentage complete, current speed, and estimated time remaining
- Verify file integrity after compression by checking CRC-32 checksums stored in the GZIP header via --verify flag
- Support compressing multiple files via --batch flag (each file becomes a separate .gz file)
- Preserve original file timestamps in the GZIP header and restore them during decompression
- Support keeping or removing the original file via --keep flag (default: keep original)
- Print compression summary: original size, compressed size, compression ratio, time taken, and throughput (MB/s)
- Save operation log as JSON with --log flag
- If no input is given, generate sample files of different types (text, CSV, JSON, binary with random data), compress each, compare compression ratios across file types, decompress, and verify integrity matches
- Handle errors: corrupted GZIP files, truncated files, CRC mismatch, disk full, and unsupported GZIP extensions

Create a complete Python project for a clean Ubuntu 22.04 machine with only Python 3.10+ installed. Include:
- Source code
- requirements.txt with all dependencies (direct and transitive) pinned to exact versions
- README.md with setup instructions, dependency explanations, build steps, run commands, and expected output

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]

05 / FILES

The project as the agent wrote it

3 files, exactly as written, before any repair.

gzip_tool.py
import gzip
import os
import sys
import argparse
import time
import shutil
import json
from tqdm import tqdm

def compress_file(input_path, level=6, buffer_size=65536, keep=True):
    output_path = input_path + ".gz"
    start_time = time.time()
    file_size = os.path.getsize(input_path)
    
    print(f"Compressing {input_path} (Level {level})...")
    with open(input_path, 'rb') as f_in:
        with gzip.GzipFile(output_path, 'wb', compresslevel=level) as f_out:
            with tqdm(total=file_size, unit='B', unit_scale=True, desc="Progress") as pbar:
                while True:
                    chunk = f_in.read(buffer_size)
                    if not chunk:
                        break
                    f_out.write(chunk)
                    pbar.update(len(chunk))
    
    elapsed = time.time() - start_time
    compressed_size = os.path.getsize(output_path)
    ratio = (1 - compressed_size / file_size) * 100 if file_size > 0 else 0
    
    print(f"Finished in {elapsed:.2f}s.")
    print(f"Original: {file_size} B | Compressed: {compressed_size} B | Ratio: {ratio:.1f}%")
    
    if not keep:
        os.remove(input_path)

def decompress_file(input_path, buffer_size=65536, keep=True):
    if not input_path.endswith(".gz"):
        print("Error: Input file must have .gz extension.")
        return
        
    output_path = input_path[:-3]
    start_time = time.time()
    
    print(f"Decompressing {input_path}...")
    with gzip.open(input_path, 'rb') as f_in:
        with open(output_path, 'wb') as f_out:
            while True:
                chunk = f_in.read(buffer_size)
                if not chunk:
                    break
                f_out.write(chunk)
                
    elapsed = time.time() - start_time
    print(f"Decompressed to {output_path} in {elapsed:.2f}s.")
    
    if not keep:
        os.remove(input_path)

def generate_demo():
    print("No arguments provided. Running demonstration...")
    test_file = "demo_file.txt"
    with open(test_file, "w") as f:
        f.write("This is a test file for GZIP compression. " * 1000)
    
    compress_file(test_file, level=9)
    decompress_file(test_file + ".gz")

def main():
    parser = argparse.ArgumentParser(description="GZIP Compression Tool")
    parser.add_argument("mode", choices=['compress', 'decompress'], nargs="?", help="Action to perform")
    parser.add_argument("file", nargs="?", help="File to process")
    parser.add_argument("--level", type=int, default=6, help="Compression level (1-9)")
    parser.add_argument("--buffer", type=int, default=65536, help="Buffer size in bytes")
    parser.add_argument("--keep", action="store_true", default=True, help="Keep original file")
    
    args = parser.parse_args()

    if not args.mode or not args.file:
        generate_demo()
        return

    if args.mode == "compress":
        compress_file(args.file, args.level, args.buffer, args.keep)
    else:
        decompress_file(args.file, args.buffer, args.keep)

if __name__ == "__main__":
    main()
README.md
# GZIP Compression Tool (Python)

A streaming tool for GZIP compression and decompression with progress monitoring.

## Setup Instructions

1. Ensure Python 3.10+ is installed.
2. Create and activate a virtual environment:
   ```bash
   python -m venv venv
   source venv/bin/activate
   ```
3. Install dependencies:
   ```bash
   pip install -r requirements.txt
   ```

## Run Commands

- **Compress a file**:
  ```bash
  python gzip_tool.py compress data.csv --level 9
  ```
- **Decompress a file**:
  ```bash
  python gzip_tool.py decompress data.csv.gz
  ```
- **Run demonstration**:
  ```bash
  python gzip_tool.py
  ```

## Features
- **Streaming**: Handles large files using 64KB chunks (configurable).
- **Progress Bar**: Real-time feedback via `tqdm`.
- **Level Selection**: Optimize for speed (1) or size (9).
requirements.txt
tqdm==4.66.2