Chilkat Gzip Class Overview
The Chilkat.Gzip class provides functionality for working with GZIP compression in both file-based and in-memory scenarios. It supports compressing and decompressing:
- Files (
.gz,.tar.gz) - Strings (with charset conversion)
- Binary data (
byte[],BinData) - Encoded data (Base64, Hex, etc.)
It also allows embedding metadata such as filenames, timestamps, and comments within the GZIP format.
Core Capabilities
1. Compression
- Compress files →
.gz - Compress strings → binary or encoded output
- Compress memory →
.gzin memory or file - In-place compression via
BinData
2. Decompression
- Uncompress
.gzfiles - Extract to memory, file, or string
- In-place decompression
- Handle encoded compressed data
3. Format Detection
- Check if data or file is GZIP (
ExamineFile,IsGzip, etc.)
4. Encoding Support
- Base64, Hex, URL, Quoted-Printable, etc.
- Encode/decode helpers included
5. Streaming Extraction
.tar.gzextraction (UnTarGz) with:- No temp files
- Constant memory usage
Key Properties
Compression Behavior
- CompressionLevel (0–9) Controls compression ratio vs speed (default = 6)
Embedded Metadata
- Filename → embedded name inside
.gz - Comment → optional text comment
- LastModStr / SetDt → timestamp inside archive
- ExtraData → custom binary metadata
Execution Control
- AbortCurrent → cancel long operations
- HeartbeatMs → interval for abort checks
Output Behavior
- UseCurrentDate → override stored timestamp on extraction
Diagnostics
- LastErrorText → detailed error/debug info
Method Categories
File-Based Compression
CompressFileCompressFile2(custom embedded filename)CompressMemToFileCompressStringToFile
File-Based Decompression
UncompressFileUncompressMemToFileUncompressBdToFile
In-Memory Operations
CompressMemoryUncompressMemoryCompressFileToMemUncompressFileToMem
️ Important limitation:
- 4GB max for uncompressed size in memory operations
String-Based Operations
CompressStringCompressStringENCUncompressStringUncompressStringENC
Supports charset conversion:
utf-8,iso-8859-1,shift_JIS, etc.
BinData / StringBuilder
CompressBd,UncompressBdCompressSb
Encoding Utilities
Encode,Decode
Format Detection
ExamineFileExamineMemoryIsGzip
Advanced / Special
UnTarGz→ extract.tar.gzsafely and efficientlyDeflateStringENC/InflateStringENC(raw deflate — not full gzip format)XfdlToXmlConverts base64+gzip XFDL data to XML
Important Notes & Gotchas
1. GZIP vs Deflate
Compress*→ produces GZIP formatDeflateStringENC→ produces raw deflate (no GZIP wrapper)
2. Embedded Filename Behavior
CompressFile2allows control over extracted filenameUncompressFileignores embedded name and uses provided output path
3. Memory Limits
- 4GB limit applies to:
CompressMemoryUncompressMemoryUncompressFileToMem
4. Charset Handling
- String compression always involves:
- Convert string → bytes using charset
- Compress bytes
5. Error Handling Pattern
Always check:
if (!success) {
Console.WriteLine(gzip.LastErrorText);
}
Summary
Chilkat.Gzip is a full-featured GZIP utility class that covers:
- File ↔ memory ↔ string workflows
- Encoding-aware compression
- Metadata embedding
- Safe
.tar.gzextraction - Format detection and validation
It’s designed to be flexible across:
- High-level use (files, strings)
- Low-level control (binary data, encoding, metadata)