A complete lossless file compression and decompression tool implemented in C++ using the Huffman Coding algorithm.
This project compresses a text file into a compact binary format and reconstructs the original file without any data loss.
- Lossless compression using Huffman Coding
- Binary bit-level encoding (real compression, not 0/1 text)
- Automatic decompression
- Stores frequency table inside file header
- Rebuilds exact Huffman Tree during decoding
- Handles padding bits safely
- CLI based menu system
-
Read input file
-
Count character frequencies
-
Build Huffman Tree (Min Heap + Greedy algorithm)
-
Generate binary codes
-
Pack bits into bytes
-
Store:
- Original file size
- Frequency table
- Encoded binary data
- Read header (size + frequency table)
- Rebuild identical Huffman tree
- Read binary bits
- Traverse tree
- Restore original text
Huffman-File-Compressor/
│
├── include/
│ ├── HuffmanNode.h
│ ├── HuffmanTree.h
│ ├── Compressor.h
│ └── Decompressor.h
│
├── src/
│ ├── HuffmanTree.cpp
│ ├── Compressor.cpp
│ └── Decompressor.cpp
│
├── input/
│ └── test.txt
│
├── output/
│ ├── compressed.bin
│ └── decompressed.txt
│
├── build/
│
└── main.cpp
g++ src/*.cpp main.cpp -o build/appbuild/app1 → Compress File
2 → Decompress File
3 → Exit
Input:
hello huffman compression project
this is my first compressor
Compressed → compressed.bin
Decompressed → decompressed.txt (identical to input)
- Greedy Algorithms
- Priority Queue (Min Heap)
- Binary Trees
- Bit Manipulation
- File Handling (Binary I/O)
- Object Oriented Programming
- Data Structures & Algorithms
This project demonstrates understanding of:
- Real file compression
- Memory-efficient encoding
- Serialization & deserialization
- Tree reconstruction
- Practical DSA implementation
Open for learning and educational use.