Skip to content

rgzip

License

A minimal, streaming gzip CLI tool in Rust with a reusable library crate.

Features

  • Minimal Dependencies — Only flate2 and clap
  • Streaming I/O — Handle files of any size
  • Reusable Library — Core logic in lib.rs for embedding
  • Flexible Output — File, stdout, or custom paths

Installation

bash
cd gzip/rust
cargo build --release

# Binary location
./target/release/rgzip

Usage

rgzip [OPTIONS] [INPUT]

ARGS:
  INPUT         Input file (default: stdin)

OPTIONS:
  -d, --decompress    Decompress mode
  -o, --output <PATH> Output file path
  -f, --force         Overwrite existing files
  -k, --keep          Keep source file after processing
  -l, --level <0-9>   Compression level (default: 6)
  -h, --help          Show help
  -V, --version       Show version

Examples

Compression

bash
# Compress file (creates file.txt.gz, deletes original)
rgzip file.txt

# Compress and keep original
rgzip -k file.txt

# Compress to specific output
rgzip -o archive.gz file.txt

# Compress from stdin
echo "hello world" | rgzip > hello.gz

# Specify compression level
rgzip -l 9 large_file.bin

Decompression

bash
# Decompress file (creates file.txt, deletes .gz)
rgzip -d file.txt.gz

# Decompress to specific output
rgzip -d -o output.txt file.txt.gz

# Decompress from stdin
rgzip -d < file.txt.gz > file.txt

Library API

rust
use rgzip::{compress_path, decompress_path, compress_reader_to_writer};
use std::path::Path;

// File to file
compress_path(Path::new("input.txt"), Path::new("output.gz"), 6)?;
decompress_path(Path::new("input.gz"), Path::new("output.txt"))?;

// Stream to stream
let stdin = io::stdin();
let stdout = io::stdout();
compress_reader_to_writer(stdin, stdout, 6)?;

Available Functions

FunctionDescription
compress_pathCompress file to file
decompress_pathDecompress file to file
compress_reader_to_pathCompress stream to file
decompress_reader_to_pathDecompress stream to file
compress_reader_to_writerCompress stream to stream
decompress_reader_to_writerDecompress stream to stream
default_output_for_compressGet default output path (file.txtfile.txt.gz)
default_output_for_decompressGet default output path (file.txt.gzfile.txt)
ensure_writableCheck output path is writable
same_pathCheck if two paths are identical
sanitize_levelClamp compression level to 0-9

Testing

bash
cargo test

Comparison with Go Implementation

See gzip/go/ for the Go implementation.

AspectRustGo
Error handlingResult<T, E> with ?if err != nil
ParallelismSingle-threaded (use rayon for parallel)Built-in goroutines
LibrarySeparate lib.rs crateSingle package

License

MIT OR Apache-2.0