An open API service indexing awesome lists of open source software.

https://github.com/tcsenpai/qrare


https://github.com/tcsenpai/qrare

Last synced: 2 months ago
JSON representation

Awesome Lists containing this project

README

          

# 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**:
```bash
git clone
cd qrare
```

2. **Install dependencies**:
```bash
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](https://sourceforge.net/projects/zbar/)

### Basic Usage

**Encode a file to QR codes**:
```bash
python src/qrare_cli.py encode document.pdf -o qrcodes/
```

**Decode QR codes back to file**:
```bash
python src/qrare_cli.py decode qrcodes/ -o recovered/
```

**Use preset configurations**:
```bash
# 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
```bash
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
```bash
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
```bash
python src/qrare_cli.py analyze IMAGES...
```

Examine QR codes and report their status without performing reconstruction.

### Examples

**Encode with custom settings**:
```bash
python src/qrare_cli.py encode large_file.bin \
--chunk-size 2048 \
--qr-version 30 \
--compression-level 6 \
-o qr_output/
```

**Decode from directory**:
```bash
python src/qrare_cli.py decode qr_output/ -o recovered/
```

**Decode from specific files**:
```bash
python src/qrare_cli.py decode qr_output/*.png -o recovered/
```

**Analyze QR codes first**:
```bash
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

```python
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

```python
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

```python
# 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

```python
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:
```bash
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
```bash
# Get encoding estimation before processing
python src/qrare_cli.py encode large_file.bin --analyze-only
```

### Batch Processing
```python
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
```python
# 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