A file compression and decompression tool built using the Huffman Encoding Algorithm.
This project demonstrates lossless data compression by encoding frequently occurring characters with shorter binary codes.
- Compress any binary/text file using Huffman Greedy Encoding Algorithm.
- Serialize and store the Huffman tree within the compressed file.
- Decompress back to the original file without loss.
- Reports file sizes and compression ratio.
- CLI-based usage: simple and effective.
- Supports extended characters and binary files.
- optional ouput_file parameter
├── Huffman.h # Header file for Huffman class
├── Huffman.cpp # implementation file for the Huffman class
├── main.cpp # main file for handling CLI
├── input.txt # Example input file
├── skeweddata.txt # file for compression demonstration
└── README.md # Project documentation
- Reads the input file and builds a frequency map.
- Constructs the Huffman Tree.
- Generates binary codes for characters.
- Serializes the tree using pre-order traversal.
- Encodes the content and writes binary data.
- Deserializes the Huffman Tree, reads delimier and padding info.
- Reads and decodes the binary data.
- Restores the original content by traversing the tree.
g++ main.cpp Huffman.cpp -o huffman./huffman compress input.txt compressed.binOr let program create a default output name (input.huf)
./huffman compress input.txt./huffman decompress compressed.bin output.txt./huffman compress input.txt compressed.bin
Compressed data written to: compressed.bin
original file size: 220.466KB
compressed file size :118.652KB
Compression ratio: 53.8189%
Decompression successful!
Restored file written to: output.txt
Restored file size: 220.466 KB