A simple and efficient file compression and decompression tool written in C using Huffman Coding, developed by Geeks 5.
This project demonstrates how lossless data compression works using Huffman encoding.
The program:
- Reads a file (text or binary)
- Calculates frequency of each byte
- Builds a Huffman Tree
- Encodes data into compressed format (
.g5) - Decodes compressed file back to original (
.txt)
- Huffman Coding (Greedy Algorithm)
- Binary Trees
- Min Heap (Priority Queue)
- Bit-level file handling
.
├── main.c → CLI interface and program flow
├── freq.h → Frequency calculation
├── huffman.h → Tree + heap + code generation
├── compress.h → Compression logic
├── decompress.h → Decompression logic
└── README.md
-
Read input file
-
Count frequency of each character
-
Build Huffman Tree
-
Generate binary codes
-
Store:
- Total characters
- Encoded Huffman tree
- Compressed data
Output file → .g5
- Read
.g5file - Reconstruct Huffman Tree
- Decode bit stream
- Write original data
Output file → .txt
Compile using GCC:
gcc main.c -o main./main <filename> --compressExample:
./main sample.txt --compressThen enter output name → creates:
output.g5
./main <filename> --decompressExample:
./main sample.g5 --decompressThen enter output name → creates:
output.txt
gcc main.c -o main
./main input.txt --compress
./main input.g5 --decompress- Lossless compression
- Custom
.g5format - Bit-level encoding
- Tree serialization
- Works on any file type
- Output filename must be entered manually
- No GUI (command line only)
- Limited error handling
- Not optimized for very large files
- Add command-line flags for output file
- Improve error handling
- Add Makefile
- Add GUI interface
- Optimize compression ratio
Geeks 5
- Bharath
- Hrushikesh
- Mukesh
- Raghav
- Shanmukh
- Compression appends
.g5automatically - Decompression appends
.txtautomatically - Empty files are not supported
Basic implementation inspired from standard Huffman Coding concepts and data structures.
This project is a practical implementation of how real-world compression systems work at a low level using bits and trees.