An adaptive marker-based compression algorithm that dynamically selects optimal compression methods for different data patterns within files. This tool analyzes your data in chunks and applies the most efficient compression method to each chunk, resulting in better overall compression ratios.
- Adaptive Compression: Automatically selects the best compression method for different parts of a file
- Multiple Compression Methods: Leverages various algorithms including zlib, lzma, bz2, zstandard, lz4, and brotli
- Marker-Based Approach: Uses pattern recognition to identify optimal compression transitions
- Graphical User Interface: Simple Gradio-based interface for easy file compression/decompression
- Command-Line Interface: For batch processing and automated workflows
- Compression Analysis: Tools to analyze and visualize compression efficiency
- Python 3.7 or higher
- pip package manager
-
Clone the repository:
git clone https://github.com/KalharPandya/adaptive-compression.git cd adaptive-compression -
Install the required dependencies:
pip install -r requirements.txt
For better compression performance, install additional compression libraries:
pip install zstandard>=0.15.0 lz4>=3.0.0 Brotli>=1.0.9Note: The LZHAM library (pylzham) requires manual installation if needed, as it's not available through pip by default.
The simplest way to try the demo is through the GUI:
-
Launch the application:
python main.py
Or explicitly specify GUI mode:
python main.py gui
-
If Gradio is not installed, you can add the
--install-gradioflag:python main.py gui --install-gradio
-
The GUI will open in your browser with the following options:
- Compress: Upload a file, configure chunk size, and compress
- Decompress: Upload a compressed .ambc file and recover the original
- Analysis: View compression statistics and performance metrics
For more advanced usage or batch processing:
python main.py compress <input_file> <output_file.ambc> [options]Options:
--chunk-size: Size of data chunks in bytes (default: 4096)--methods: Comma-separated list of compression methods to use--disable-methods: Comma-separated list of compression methods to disable--show-progress: Display a progress bar during compression
Example:
python main.py compress large_dataset.csv compressed_data.ambc --chunk-size 8192 --show-progresspython main.py decompress <input_file.ambc> <output_file> [options]Options:
--show-progress: Display a progress bar during decompression
Example:
python main.py decompress compressed_data.ambc original_data.csv --show-progresspython main.py analyze [options]Options:
--results-file: Path to compression history file (default: compression_results/compression_history.json)--output-dir: Directory to save analysis charts and reports (default: analysis_output)
Example:
python main.py analyze --results-file my_results.json --output-dir my_analysisThe chunk size is a critical parameter that affects compression performance:
- Smaller chunks (e.g., 1024 bytes): More granular method selection but higher overhead
- Larger chunks (e.g., 16384 bytes): Less overhead but potentially lower compression efficiency
- Default (4096 bytes): Good balance for most use cases
You can adjust the chunk size in the GUI using the slider or in the CLI using the --chunk-size parameter.
Files compressed with this tool use the .ambc extension (Adaptive Marker-Based Compression) and contain:
- File header with metadata
- Compression method table
- Compressed data chunks with method identifiers
If you encounter import errors related to the Gradio interface:
-
Ensure Gradio is installed and up to date:
pip install --upgrade gradio>=3.0.0 -
Fix import cycles by making sure the Python path is correctly set:
export PYTHONPATH=$PYTHONPATH:/path/to/adaptive-compression
-
If you see errors about missing modules like
Unable to import gradio_components, check your Python path:python -c "import sys; print(sys.path)"
If you encounter errors related to compression methods:
-
Check which compression libraries are available:
python -c "from compression_fix import check_compression_libraries; print(check_compression_libraries())" -
Install any missing compression libraries as recommended above.
-
If an error occurs specifically with one compression method, you can still use the tool with the other methods.
If the GUI fails to display:
-
Check if Gradio is properly installed:
pip install gradio>=3.0.0 -
Make sure you have a browser available for the GUI to open in.
-
If you're in a headless environment, try using the command-line interface instead.
- Large Dataset Compression: Efficiently compress large CSV or JSON datasets with mixed content types
- Log File Archiving: Compress log files that contain both structured and unstructured data
- Mixed Media Storage: Optimize storage of files that contain both text and binary data
- Data Pipeline Integration: Add to ETL processes to reduce data transfer sizes
The adaptive compression typically achieves:
- 5-15% better compression ratios compared to using a single method
- Slightly longer compression time due to analysis overhead
- Similar decompression speed to standard methods
For a list of known issues and limitations, please see the KNOWN_ISSUES.md file.
For information on adding new compression methods or customizing the tool, please see the SETUP.md file.