A powerful and modular Python CLI tool for converting binary files to QR codes and reconstructing them back to the original files. Features compression, error correction, file integrity verification, and a comprehensive modular architecture.
- π Bidirectional Conversion: Convert any binary file to QR codes and back
- ποΈ Smart Compression: Reduce QR code count with configurable zlib compression
- π‘οΈ Error Correction: Built-in QR code error correction for reliable scanning
- π Integrity Verification: SHA-256 hash verification ensures data integrity
- ποΈ Flexible Configuration: Customizable chunk sizes, QR versions, and compression levels
- β‘ Preset Modes: Fast, compact, and robust presets for different use cases
- ποΈ Modular Architecture: Clean, maintainable codebase with separate concerns
- π₯οΈ Cross-Platform: Works on Windows, macOS, and Linux
- π Progress Analysis: Analyze QR codes before decoding for validation
-
Clone the repository:
git clone <repository-url> cd qrare
-
Install dependencies:
pip install -r requirements.txt
-
Install ZBar library (required for QR code reading):
- Ubuntu/Debian:
sudo apt-get install libzbar0 - macOS:
brew install zbar - Windows: Download from SourceForge
- Ubuntu/Debian:
Encode a file to QR codes:
python src/qrare_cli.py encode document.pdf -o qrcodes/Decode QR codes back to file:
python src/qrare_cli.py decode qrcodes/ -o recovered/Use preset configurations:
# Fast encoding (lower compression, larger chunks)
python src/qrare_cli.py encode data.bin --preset fast
# Compact encoding (maximum compression, minimal QR codes)
python src/qrare_cli.py encode data.bin --preset compact
# Robust encoding (maximum error correction)
python src/qrare_cli.py encode data.bin --preset robustpython src/qrare_cli.py encode FILE [OPTIONS]Options:
-o, --output-dir DIR: Directory to save QR code images (default:./qrcodes)-c, --chunk-size BYTES: Size of binary chunks (default: 1024)--qr-version 1-40: QR code version, higher = more capacity (default: 40)-z, --compression-level 0-9: Compression level, 0=none, 9=best (default: 9)--preset {fast,compact,robust}: Use preset configuration
python src/qrare_cli.py decode IMAGES... [OPTIONS]Options:
-o, --output-dir DIR: Directory to save reconstructed file (default:./output)--analyze-only: Only analyze QR codes without reconstructing
python src/qrare_cli.py analyze IMAGES...Examine QR codes and report their status without performing reconstruction.
Encode with custom settings:
python src/qrare_cli.py encode large_file.bin \
--chunk-size 2048 \
--qr-version 30 \
--compression-level 6 \
-o qr_output/Decode from directory:
python src/qrare_cli.py decode qr_output/ -o recovered/Decode from specific files:
python src/qrare_cli.py decode qr_output/*.png -o recovered/Analyze QR codes first:
python src/qrare_cli.py analyze qr_output/The refactored codebase follows a clean, modular architecture:
src/qrare/
βββ core/ # Core functionality
β βββ config.py # Configuration management
β βββ converter.py # Main converter class
β βββ encoder.py # QR encoding logic
β βββ decoder.py # QR decoding logic
βββ cli/ # Command-line interface
β βββ main.py # CLI entry point
β βββ commands.py # Command implementations
βββ utils/ # Utility modules
βββ exceptions.py # Custom exception classes
βββ file_ops.py # File operations
βββ path_utils.py # Path handling utilities
- π§ Config System: Centralized configuration with validation and presets
- β‘ Encoder/Decoder: Separate, focused classes for encoding and decoding
- π οΈ File Operations: Robust file handling with comprehensive error management
- π― Exception Handling: Specific exception types for better error reporting
- π CLI Interface: Clean argument parsing and command execution
from qrare import BinaryQRConverter
# Create converter
converter = BinaryQRConverter(chunk_size=1024, compression_level=9)
# Encode file
qr_paths = converter.encode_file("document.pdf", "qr_output/")
print(f"Created {len(qr_paths)} QR codes")
# Decode back
reconstructed = converter.decode_qr_images(qr_paths, "recovered/")
print(f"Reconstructed: {reconstructed}")from qrare import BinaryQRConverter, QRConfig, CompressionLevel, ErrorCorrectionLevel
# Custom configuration
config = QRConfig(
chunk_size=2048,
qr_version=30,
compression_level=CompressionLevel.BALANCED,
error_correction=ErrorCorrectionLevel.HIGH,
box_size=8,
fill_color="darkblue"
)
converter = BinaryQRConverter(config=config)# Optimized for speed
fast_converter = BinaryQRConverter.create_fast_converter()
# Optimized for minimal QR codes
compact_converter = BinaryQRConverter.create_compact_converter()
# Optimized for error recovery
robust_converter = BinaryQRConverter.create_robust_converter()from qrare.core.encoder import QREncoder
from qrare.core.decoder import QRDecoder
from qrare.core.config import QRConfig
# Use encoder and decoder separately
encoder = QREncoder(QRConfig.create_compact_config())
decoder = QRDecoder()
# Encode
qr_paths = encoder.encode_file("data.bin", "qr_codes/")
# Analyze before decoding
analysis = decoder.analyze_qr_images(qr_paths)
print(f"Analysis: {analysis['readable_qrs']} readable QR codes")
# Decode
result = decoder.decode_qr_images(qr_paths, "output/")- Small (512-1024 bytes): More QR codes, better error recovery
- Medium (1024-2048 bytes): Balanced approach
- Large (2048-4096 bytes): Fewer QR codes, less error recovery
- 1-10: Small capacity, simple codes
- 11-25: Medium capacity, good balance
- 26-40: High capacity, complex codes
- 0: No compression (fastest)
- 1-3: Fast compression
- 4-6: Balanced compression
- 7-9: Best compression (slowest)
- LOW (~7%): Maximum data capacity
- MEDIUM (~15%): Balanced
- QUARTILE (~25%): Good error recovery
- HIGH (~30%): Maximum error recovery
The examples/ directory contains comprehensive usage examples:
basic_usage.py: Core functionality demonstrationadvanced_usage.py: Advanced features and error handling
Run examples:
python examples/basic_usage.py
python examples/advanced_usage.py- π File Reading: Binary file is read into memory
- ποΈ Compression: Data is compressed using zlib to reduce size
- βοΈ Chunking: Compressed data is split into manageable chunks
- π Metadata: Each chunk includes index, total count, filename, and hash
- π³ QR Generation: Each chunk becomes a QR code with embedded metadata
- πΎ Storage: QR codes are saved as PNG images with descriptive names
Reconstruction reverses the process:
- π QR Reading: QR codes are scanned and decoded
- β Validation: Chunks are validated and sorted by index
- π Assembly: Chunks are reassembled into compressed data
- π¦ Decompression: Data is decompressed to original format
- π Verification: SHA-256 hash confirms file integrity
# Get encoding estimation before processing
python src/qrare_cli.py encode large_file.bin --analyze-onlyfiles = ["doc1.pdf", "doc2.bin", "doc3.txt"]
for file_path in files:
qr_paths = converter.encode_file(file_path, f"qr_{file_path.stem}/")
print(f"{file_path}: {len(qr_paths)} QR codes")# Analyze QR codes for completeness
analysis = converter.analyze_qr_images(qr_paths)
for filename, info in analysis['chunk_info'].items():
if not info['is_complete']:
missing = set(range(info['total_chunks'])) - set(info['found_chunks'])
print(f"File {filename} missing chunks: {sorted(missing)}")β "Missing ZBar library"
- Install ZBar using the instructions in the Prerequisites section
β "QR code decoding fails"
- Ensure QR codes are clear and undamaged
- Try increasing error correction level
- Check that all QR codes are present
β "File too large"
- Increase chunk size:
--chunk-size 4096 - Use higher QR version:
--qr-version 40 - Consider splitting large files
β "Invalid QR version"
- Use version between 1-40
- Higher versions support more data but need better scanning
- For speed: Use
--preset fastor lower compression levels - For size: Use
--preset compactor higher compression levels - For reliability: Use
--preset robustor higher error correction - For large files: Increase chunk size to reduce QR code count
- β¨ Complete modular architecture refactoring
- β¨ New preset configurations (fast/compact/robust)
- β¨ Enhanced error handling and validation
- β¨ Separate encoder/decoder classes
- β¨ Comprehensive configuration system
- β¨ Analysis and estimation features
- β¨ Improved CLI with new commands
- β¨ Extensive documentation and examples
- π§ Backward compatibility maintained
- π― Basic encoding/decoding functionality
- π§ Simple CLI interface
- π¦ Compression and integrity verification
Contributions are welcome! The modular architecture makes it easy to:
- Add new encoding/decoding formats
- Implement additional compression algorithms
- Create new preset configurations
- Enhance error recovery mechanisms
- Improve CLI functionality
MIT License - see LICENSE file for details.
- ZBar: QR code reading functionality
- qrcode: QR code generation
- Pillow: Image processing
- Original QRare: Foundation for this enhanced version
QRare v0.2.0 | Modular β’ Reliable β’ Extensible