Skip to content

Yassin-pixel-bit/compress-web

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

compress web

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.

features

  • 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)

Compression Algorithms

  • 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, and PNG file formats, offering a good balance between compression ratio and speed.

  • zipfile module: Uses Python's built-in zipfile library 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.

Project Structure

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

screenshots

Home page

Dark mode light mode

Compression results

Dark mode light mode

ZIP-compatible tab

Dark mode light mode

Code Overview

  • 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.

Design Decisions

  • 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 zipfile to 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.

Future Improvements

  • Add more themes.
  • Make the algorithms faster.
  • file streaming for large files.

Getting Started

Open you command line interface and run the following commands

  1. Clone the repository:
git clone https://github.com/Yassin-pixel-bit/compress-web.git
  1. Change into the project directory:
cd compress-web
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the app:
flask run

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages