Run-length encoding (RLE) is a form of lossless data compression in which runs of data (consecutive occurrences of the same data value) are stored as a single occurrence of that data value and a count of its consecutive occurrences, rather than as the original run.
This project provides a fast and simple implementation of Run-Length Encoding (RLE) in Rust, along with utilities for benchmarking and testing. It includes:
- A Rust CLI tool for compressing and decompressing files using RLE.
- Utility functions for efficient file I/O with progress bars.
- A C++ utility to generate large input files for testing and benchmarking.
rl_encoding/
├── Cargo.toml # Rust project manifest
├── generate_input.cpp # C++ utility to generate large input files
└── src/
├── main.rs # entry point
├── rle.rs # RLE compression/decompression
├── utils.rs # File I/O utilities with progress bars
└── lib.rs # (Optional) Rust library file
Compile the generate_input.cpp with aggressive compilation flags as it generates large output file (~100MB)
g++ generate_input.cpp -o gen -O3 -std=c++20 -flto -march=native
./genThis will generate a large_input.txt which can be used to test and benchmark this project.
cargo run -- compress <input_file> <output_file>cargo run -- decompress <input_file> <output_file>You can verify that decompression restores the original data:
diff <input> <output>
# No output means files are identical- Efficient file reading and writing with progress bars (see
src/utils.rs). - Simple and fast RLE compression/decompression (see
src/rle.rs). - Example C++ generator for large test files.
This project is licensed under the MIT License.