Video Demo: https://youtu.be/iQRQ7Ou1-QM
A simple Flask-based web application that allows users to compress files using a custom implementation of these well-know algorithms: LZ77 and DEFLATE or directly use zipfile module from python to allow their files to be decompressed using WinRAR, 7zip, etc. Users can upload a file, choose the desired compression method, and download the compressed version.
- Web interface for file compression
- Upload and compress files
- Choose between LZ77 and DEFLATE compression or python's
zipfile - Minimal and easy-to-understand UI
- Custom implementations of both algorithms (LZ77 and DEFLATE)
-
LZ77: LZ77 is a classic lossless data compression algorithm that works by finding repeated sequences of data (patterns) within a sliding window and replacing them with references to previous occurrences. This reduces redundancy and achieves compression without losing any information. LZ77 is the foundation for many modern compression methods and is especially effective on files with repeated patterns or sequences.
-
DEFLATE: DEFLATE is a widely used lossless compression algorithm that combines the LZ77 algorithm with Huffman coding. First, it uses LZ77 to replace repeated data with references, then applies Huffman coding to further compress the data by encoding more frequent symbols with shorter codes. DEFLATE is the core algorithm behind
ZIP,gzip, andPNGfile formats, offering a good balance between compression ratio and speed. -
zipfile module: Uses Python's built-in
zipfilelibrary to create standard ZIP archives. Files compressed with this option can be easily decompressed using common tools like WinRAR, 7-Zip, or the built-in ZIP support in most operating systems.
compress-web/
├── app.py # Main Flask app
├── compression_algos/
│ ├── deflate.py # DEFLATE compression logic
│ └── lz77.py # LZ77 compression logic
│ └── compress_helper.cpp
├── templates/
│ └── layout.html # HTML layout
| └── index.html # The main page
| └── zip.html # The zip-compatable page
├── static/ # Static files
│ └── styles.css
│ └── website_icon.ico
├── compressed/ # where the compressed files are temporary stored
├── uploads/ # where the compressed files are temporary stored
├── requirements.txt # Python dependencies
└── README.md # Project info
- app.py: The main flask app. this handles routing, files upload, compressing files, and serves the user interface.
- compression_algos/lz77.py: This is my custom implementation of lz77. It contains the lz77 class and the compress/decompress logic.
- compression_algos/deflate.py: This is my custom implementation of Deflate. It combines lz77 with huffman coding. I use my lz77 class here and created the huffman class here.
- templates/layout.html: Base HTML layout used by other pages.
- templates/index.html: The main interface for uploading and compressing files.
- templates/zip.html: Separate interface for creating ZIP-compatible files.
- static/styles.css: CSS for light and dark modes.
- requirements.txt: Lists the Python dependencies that need to be installed.
- compressed: A folder that temporarily holds the compressed files.
- uploads: A folder that temporarily holds the uploaded files.
- I chose Flask for its simplicity and because it's beginner-friendly yet powerful enough for routing and file handling.
- I implemented my own LZ77 and DEFLATE logic instead of using existing libraries to better understand how compression works, challenge myself and learn new things.
- I added a ZIP-compatible mode using Python’s built-in
zipfileto give users the freedom of choosing between my algorithms and the standard algorithm. - The UI includes both light and dark themes to give users some control over the website's UI.
- Compressed and uploaded files are temporarily stored in folders and cleared after session ends.
- I decided to split my algorithms into different files to make my code cleaner and easier to read and manage.
- Add more themes.
- Make the algorithms faster.
- file streaming for large files.
Open you command line interface and run the following commands
- Clone the repository:
git clone https://github.com/Yassin-pixel-bit/compress-web.git
- Change into the project directory:
cd compress-web
- Install dependencies:
pip install -r requirements.txt
- Run the app:
flask run