Skip to content

tcsenpai/qrare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

21 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

QRare - Binary QR Converter

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.

✨ Features

  • πŸ”„ 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

πŸš€ Quick Start

Installation

  1. Clone the repository:

    git clone <repository-url>
    cd qrare
  2. Install dependencies:

    pip install -r requirements.txt
  3. Install ZBar library (required for QR code reading):

    • Ubuntu/Debian: sudo apt-get install libzbar0
    • macOS: brew install zbar
    • Windows: Download from SourceForge

Basic Usage

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 robust

πŸ“– Detailed Usage

Command Line Interface

Encode Command

python 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

Decode Command

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

Analyze Command

python src/qrare_cli.py analyze IMAGES...

Examine QR codes and report their status without performing reconstruction.

Examples

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/

πŸ—οΈ Architecture

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

Key Components

  • πŸ”§ 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

πŸ’» Programmatic Usage

Basic Example

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}")

Advanced Configuration

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)

Preset Configurations

# 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()

Modular Usage

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/")

πŸ“Š Configuration Options

Chunk Size

  • 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

QR Code Version

  • 1-10: Small capacity, simple codes
  • 11-25: Medium capacity, good balance
  • 26-40: High capacity, complex codes

Compression Level

  • 0: No compression (fastest)
  • 1-3: Fast compression
  • 4-6: Balanced compression
  • 7-9: Best compression (slowest)

Error Correction

  • LOW (~7%): Maximum data capacity
  • MEDIUM (~15%): Balanced
  • QUARTILE (~25%): Good error recovery
  • HIGH (~30%): Maximum error recovery

πŸ§ͺ Examples

The examples/ directory contains comprehensive usage examples:

  • basic_usage.py: Core functionality demonstration
  • advanced_usage.py: Advanced features and error handling

Run examples:

python examples/basic_usage.py
python examples/advanced_usage.py

πŸ” How It Works

  1. πŸ“ File Reading: Binary file is read into memory
  2. πŸ—œοΈ Compression: Data is compressed using zlib to reduce size
  3. βœ‚οΈ Chunking: Compressed data is split into manageable chunks
  4. πŸ“ Metadata: Each chunk includes index, total count, filename, and hash
  5. πŸ”³ QR Generation: Each chunk becomes a QR code with embedded metadata
  6. πŸ’Ύ Storage: QR codes are saved as PNG images with descriptive names

Reconstruction reverses the process:

  1. πŸ” QR Reading: QR codes are scanned and decoded
  2. βœ… Validation: Chunks are validated and sorted by index
  3. πŸ”— Assembly: Chunks are reassembled into compressed data
  4. πŸ“¦ Decompression: Data is decompressed to original format
  5. πŸ”’ Verification: SHA-256 hash confirms file integrity

πŸŽ›οΈ Advanced Features

Estimation

# Get encoding estimation before processing
python src/qrare_cli.py encode large_file.bin --analyze-only

Batch Processing

files = ["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")

Error Recovery

# 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)}")

πŸ› οΈ Troubleshooting

Common Issues

❌ "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

Performance Tips

  • For speed: Use --preset fast or lower compression levels
  • For size: Use --preset compact or higher compression levels
  • For reliability: Use --preset robust or higher error correction
  • For large files: Increase chunk size to reduce QR code count

🏷️ Version History

v0.2.0 (Current)

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

v0.1.0 (Legacy)

  • 🎯 Basic encoding/decoding functionality
  • πŸ”§ Simple CLI interface
  • πŸ“¦ Compression and integrity verification

🀝 Contributing

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

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ™ Acknowledgments

  • 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

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors