A custom file compression tool built in C++ that implements the Huffman Coding algorithm. It reduces file sizes by analyzing character frequencies and generating variable-length binary codes, packing data down to the individual bit level.
- Bit-Level Manipulation: Implements a custom
BitWriterandBitReaderto handle raw binary I/O, allowing storage of non-byte-aligned codes (e.g., 3-bit sequences). - Custom File Format: Generates a binary file with a metadata header, enabling the tool to reconstruct the compression tree without external files.
- Deterministic Compression: Uses
std::mapand tie-breaking logic to ensure the compression tree is identical every time, preventing data corruption across different systems. - End-to-End Pipeline: Handles the full lifecycle: Frequency Analysis -> Tree Construction -> Encoding -> Decoding.
- Frequency Analysis: Scans the input text to count how often each character appears.
- Tree Construction: Builds a Binary Tree (Priority Queue) where frequent characters (like 'e') are near the top and rare characters (like 'z') are at the bottom.
- Code Generation: Traverses the tree to assign binary codes. Going left adds a
0, going right adds a1. - Bit Packing: Buffers these codes into 8-bit chunks (bytes) and flushes them to a
.binfile. - Decompression: Reads the file header to rebuild the exact same tree, then follows the raw bits to trace paths back to the original characters.
The current build runs a demonstration of the compression flow on a specific file.
-
Prepare the Data: Ensure you have a folder named
resourcesin your project directory containing a file namedinput.txt. -
Run the Program:
./HuffmanZipper
-
Check Results: The program will generate:
resources/output.bin(The compressed binary file).resources/restored.txt(The decompressed text, identical to input).
It will also print statistics to the console:
Original Bits for 'a': 8 Compressed Bits for 'a': 3 SUCCESS: The math checks out.
- Prerequisites: Visual Studio 2022 (or any standard C++ compiler).
- Clone the repo:
git clone https://github.com/Dronquavious/HuffmanZipper.git
- Open Project: Open
HuffmanZipper.slnxin Visual Studio. - Build: Press
Ctrl + Shift + Bor click Build Solution.
src/: Main application source code.resources/: Input text files and output binary data.
- Data Structures: Priority Queues (Min-Heap), Binary Trees, Maps.
- Systems Programming: Bitwise operators (
<<,>>,&,|), Binary File Streams, Memory Management.
This project is open source and under the MIT License. Feel free to use it for learning or as a base for your own project!
If you have questions, feedback, or want to discuss the project, you can reach me at:
- GitHub: @Dronquavious
- Email: tambweamani@gmail.com
Feel free to reach out — I’m happy to talk about the project or help you get started.