This project implements the Huffman coding algorithm for file compression and decompression using C++. It offers a command-line interface to efficiently compress and decompress files.
- Compression: Compress files using Huffman coding.
- Decompression: Restore files to their original format.
- Cross-Platform: Supports Linux and Windows.
- Modular Code: Well-organized and maintainable codebase.
- A C++ compiler (e.g., g++).
makeutility for building the project.valgrindfor memory leak detection (optional, used in tests).
Run the following command in your terminal:
makeThis command generates the executable named main.
To compress a file, invoke the program with the C command, specifying the input and output files:
./main C input.txt compressed.huffinput.txt: File to compress.compressed.huff: Compressed output file.
To decompress a file, use the D command, followed by the compressed file and the desired output file:
./main D compressed.huff output.txtcompressed.huff: File to decompress.output.txt: Decompressed output file.
The project includes several predefined test cases:
-
To compress test file 1:
make exeC1
-
To decompress test file 1:
make exeD1
-
Similar commands exist for test files 2 and 3 (
exeC2,exeD2,exeC3,exeD3). -
To run all tests with integrity verification:
make run-all-tests
This will compress and decompress all test files, then compare the original and recovered files to ensure data integrity.
- huffman.hpp: Header file containing the definitions for the HuffmanCoder class and related data structures.
- huffman.cpp: Implementation of the HuffmanCoder class, including the compression and decompression algorithms.
- main.cpp: Entry point managing command-line arguments and invoking the appropriate methods.
- Makefile: Build script with test automation support.
- Test Files:
input1.txt,input2.txt, andinput3.txtfor testing compression and decompression.
To remove generated object files, executables, and test outputs, run:
make cleanThis command deletes:
- All
.ofiles. - The executable (
main). - Generated
.hufffiles. - Output text files from decompression.
- The program operates in binary mode, ensuring proper handling of all file types.
- Compression efficiency depends on the frequency of characters; files with repetitive data typically achieve better compression.
- Files with uniform character distribution might result in larger output files due to overhead from storing the Huffman tree.
- Valgrind is used during testing to detect memory leaks.
Feel free to report issues or suggest improvements by opening an issue or submitting a pull request.
To create a zip archive of the project files:
make zip