Overview
TeeBI provides a flexible compression system through theTCompression class with pluggable compression engines. Compression is essential for:
- Reducing file sizes for storage
- Faster network transmission
- Efficient binary stream persistence
- Web server data transfer
Default Compression Engine
By default, TeeBI usesSystem.Zip from the Delphi RTL:
Compression Plugins
TeeBI supports multiple compression engines through a plugin architecture.Available Plugins
- TSystemCompression - Default, uses
System.Zip(Delphi RTL) - TSynZipCompression - mORMot SynZip engine
- TSynLZCompression - mORMot SynLZ engine (faster)
- TSnappyCompression - Google Snappy (x64 only)
Switching Compression Engines
Using SynLZ (Recommended for Speed)
Using SynZip
Using Snappy (x64 only)
BI.Compression.Snappy.pas:11-13:
Basic Usage
Compressing a Stream
Decompressing a Stream
Decompressing ZIP Files
Plugin Architecture
FromBI.Compression.pas:48-74:
Compression Engine Comparison
System.Zip (Default)
Pros:- Built into Delphi RTL
- No external dependencies
- Standard ZIP format
- Supports encrypted ZIPs (Delphi 10.2+)
- Slower than alternatives
- Larger compressed size
SynLZ (mORMot)
Pros:- Very fast compression/decompression
- Low CPU overhead
- Smaller memory footprint
- Excellent for real-time compression
- Requires mORMot library
- Proprietary format (not standard ZIP)
- Lower compression ratio than ZIP
SynZip (mORMot)
Pros:- Faster than System.Zip
- Standard ZIP format
- Good compression ratio
- Requires mORMot library
- Slower than SynLZ
Snappy (Google)
Pros:- Extremely fast decompression
- Predictable performance
- Good for streaming data
- x64 only
- Requires Snappy library
- Proprietary format
- Lower compression ratio
Web Server Compression
The TeeBI Web Server uses compression transparently:BI.Web.pas:370-382:
Important Notes
Client-Server Compatibility
FromBI.Compression.SynZip.pas:31-37:
Both sides of the communication (client and server) must use the same compression plugin.If server uses SynLZ, clients must also use SynLZ:
Password-Protected ZIPs
Encrypted ZIP support requires Delphi 10.2 (Tokyo) or later:Memory Considerations
Compression creates temporary memory streams. For very large datasets:- Monitor memory usage
- Consider streaming compression (process in chunks)
- Free compressed streams promptly
Best Practices
-
Choose Based on Need:
- Speed: Use SynLZ
- Compatibility: Use System.Zip
- Balance: Use SynZip
- Web Transfer: Always enable compression
- Large Files: Stream data in chunks when possible
- Testing: Benchmark with your actual data
- Consistency: Use same plugin on client and server
