A web-based application that compresses and decompresses text files using Huffman coding algorithm.
This application provides a simple and intuitive interface for users to compress text files and reduce their size without losing any information. The implementation uses the Huffman coding algorithm, which creates variable-length codes for characters based on their frequency in the text.
- Text File Compression: Upload any text file and download its compressed version (.bin)
- File Decompression: Upload compressed files and recover the original text
- User-Friendly Interface: Drag and drop functionality with intuitive design
- Efficient Compression: Achieves approximately 47% reduction in file size
- Lossless Compression: Guarantees that the decompressed file is identical to the original
- Backend: Python, Flask
- Frontend: HTML, CSS, JavaScript, Bootstrap
- Algorithm: Huffman Coding
- Serialization: Python's pickle library
-
Compression Process:
- Analyzes character frequencies in the input text
- Constructs a Huffman tree based on these frequencies
- Generates a dictionary of variable-length binary codes
- Replaces each character with its corresponding code
- Stores frequency information in the file header
- Outputs a compressed binary file
-
Decompression Process:
- Reads the frequency information from the file header
- Reconstructs the Huffman tree
- Decodes the binary data back to the original text
- Returns the original text file
-
Clone the repository:
git clone https://github.com/satvik202/File-Compression-Huffman-coding/ cd File-Compression-Huffman-coding -
Install the required packages:
pip install flask -
Run the application:
python app.py -
Open your browser and navigate to:
http://127.0.0.1:5000/
huffman-file-compressor/
├── app.py # Flask application
├── huffman.py # Huffman coding implementation
├── templates/
│ └── index.html # Frontend interface
└── uploads/ # Directory for uploaded files
-
Compressing a File:
- Click on the upload area or drag and drop a text file
- Click "Compress File"
- The compressed file will be downloaded automatically
-
Decompressing a File:
- Click on the upload area in the decompression section
- Upload a previously compressed .bin file
- Click "Decompress File"
- The original text file will be downloaded automatically
The Huffman coding algorithm creates an optimal prefix code for lossless data compression. It works by:
- Calculating the frequency of each character in the text
- Building a binary tree where characters with higher frequencies have shorter paths
- Generating variable-length codes for each character
- The most frequent characters get shorter codes, while less frequent ones get longer codes
This approach minimizes the overall size of the encoded text.
This project is licensed under the MIT License - see the LICENSE file for details.
- This project implements the Huffman coding algorithm developed by David A. Huffman
- Frontend design inspired by modern web applications