Gzip Dart Reference Documentation
CkGzip
Current Version: 11.6.1
Chilkat.Gzip
Compress files to
Work with byte arrays and
Compress and uncompress strings with explicit charset handling for text
data that must round-trip correctly.
Handle GZIP data represented as Base64, hex, or other supported encoded
forms when binary data must be carried as text.
Set or inspect metadata such as original filename, modified time,
comments, and extra data stored in the GZIP header.
Extract
For an extended overview, see
Gzip Class Overview.
Compress, decompress, inspect, and convert GZIP data in files or memory.
Chilkat.Gzip provides GZIP compression and decompression for
file-based and in-memory workflows. It can compress and uncompress files,
strings, byte arrays, BinData, and encoded data such as Base64
or hex. It also supports .tar.gz extraction, gzip metadata such
as original filename, timestamp, and comments, and inspection of GZIP header
information without fully expanding the compressed data.
File compression
.gz, uncompress .gz files,
and write decompressed output directly to disk.
Memory-based data
Chilkat.BinData for applications
that need compression or decompression without temporary files.
String workflows
Encoded GZIP data
GZIP metadata
Tar-gzip and XFDL
.tar.gz archives and decode XFDL content that uses
gzip-related encodings.
Gzip when the data is a single GZIP stream, a
.gz file, or a .tar.gz archive. For ZIP archives,
use Chilkat.Zip; for raw deflate or zlib-style compression, use
Chilkat.Compression.
Object Creation
// pubspec.yaml:
// dependencies:
// chilkat: ^11.6.1
import 'package:chilkat/chilkat.dart';
// Once per process, before any other Chilkat call:
Chilkat.unlockBundle('Anything for 30-day trial'); // shorthand for CkGlobal().unlockBundle(..)
final gzip = CkGzip();
// ... the native object is released when `gzip` is garbage collected, or now with gzip.dispose().Creates the underlying native Chilkat object. Use a CkGzip only from the isolate that created it: Chilkat objects cannot be sent between isolates. Every call is synchronous; in a Flutter app, run long operations (network, large files) inside Isolate.run, creating the Chilkat objects inside the isolate.
Releases the native object immediately instead of waiting for garbage collection (useful for a large CkBinData or an open socket). Calling it more than once is harmless; any other use of the object afterwards throws a StateError. isDisposed tells whether it has been called.
Errors
A method that can fail throws a ChilkatException: a method whose only outcome is success or failure returns void and throws on failure; a method producing a String or an object returns it and throws where Chilkat would have returned null. The exception carries the object's LastErrorText at the time of the failure (lastErrorText), the class and method names (className, methodName) and a one-line message. Properties never throw, and methods that answer a question (has..., is..., ...) return a plain bool.
try {
gzip.someMethod(...);
} on ChilkatException catch (e) {
print(e); // CkGzip.someMethod failed: <reason>
print(e.lastErrorText); // the full Chilkat log of the failed call
}
Properties
AbortCurrent
bool get abortCurrent
set abortCurrent(bool value)
Set this property to to request that the currently running operation be aborted.
This is useful for long-running operations such as large file compression or decompression.
Methods that complete quickly are generally not affected.
true
If no method is currently running, the property is automatically reset to
when the next method begins. After an abort occurs, it is also reset to false.
Both synchronous and asynchronous operations can be aborted. For synchronous calls, another
thread must set this property.
false
Comment
String get comment
set comment(String value)
An optional comment to embed in the Gzip file when a Compress* method is called.
CompressionLevel
int get compressionLevel
set compressionLevel(int value)
Controls the compression level used when creating Gzip data. The value can range from
0 to 9.
0= no compression9= maximum compression
The default value is 6, which is a typical balance between compression size and speed.
Higher levels may take significantly more CPU time while producing only slightly smaller output,
depending on the data.
DebugLogFilePath
String get debugLogFilePath
set debugLogFilePath(String value)
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
Filename
String get filename
set filename(String value)
The filename to embed in the Gzip file when a Compress* method is called.
Some Gzip extraction tools use this embedded filename as the default output filename.
HeartbeatMs
int get heartbeatMs
set heartbeatMs(int value)
Specifies the interval, in milliseconds, between AbortCheck event callbacks.
These callbacks allow an application to cancel certain long-running operations before they finish.
The default value is 0, which means no AbortCheck callbacks are triggered.
LastErrorHtml
String get lastErrorHtml
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
String get lastErrorText
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
String get lastErrorXml
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
bool get lastMethodSuccess
set lastMethodSuccess(bool value)
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
LastModStr
String get lastModStr
set lastModStr(String value)
Specifies the last-modified date/time to embed in the Gzip file when a
Compress* method is called.
The value must be provided as an RFC 822 formatted date/time string.
Example:
Sun, 12 Apr 2026 12:45:26 GMT
If this property is not set, the current system date/time is used automatically.
UseCurrentDate
bool get useCurrentDate
set useCurrentDate(bool value)
Controls the last-modified date/time assigned to files created by Uncompress* methods.
When set to , the extracted file uses the current date/time instead of the
date/time stored in the Gzip data.
true
VerboseLogging
bool get verboseLogging
set verboseLogging(bool value)
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
String get version
Methods
CompressBd
Compresses the contents of a BinData object in place, replacing the original data
with Gzip-compressed data.
Returns normally on success; throws a ChilkatException on failure.
CompressFile
Compresses a file and writes the result as a Gzip file, typically with a .gz extension.
Returns normally on success; throws a ChilkatException on failure.
CompressFile2
Compresses a file and writes the result as a Gzip file, while allowing a different filename to be embedded inside the Gzip data.
The inFilename parameter is the actual file on disk. The
parameter is the filename stored in the Gzip header and may be used
by extraction tools as the output filename.
srcPath
Returns normally on success; throws a ChilkatException on failure.
CompressFileBd
Compresses a file and stores the resulting Gzip data in a BinData object.
The compressed output is held in memory. The maximum compressed size is 4 GB.
Returns normally on success; throws a ChilkatException on failure.
CompressSb
Compresses the text contained in a StringBuilder and writes the Gzip-compressed
result to a BinData object.
Before compression, the string is converted to bytes using the specified character set, such as
utf-8, iso-8859-1, or shift_JIS.
Returns normally on success; throws a ChilkatException on failure.
CompressStringENC
Compresses a string and returns the Gzip-compressed data as an encoded string.
The input string is first converted to bytes using the specified character set. The compressed
binary data is then encoded using the requested encoding, such as base64,
hex, url, base32, or quoted-printable.
Throws a ChilkatException on failure (where the description says null is returned, the Dart method throws instead).
CompressStringToFile
Compresses a string and writes the resulting Gzip data to a file.
The string is first converted to bytes using the character set specified by
destCharset.
Returns normally on success; throws a ChilkatException on failure.
GetGzipInfo
Retrieves metadata stored in a Gzip file and returns the information in a
JsonObject.
The metadata is returned using the following JSON structure:
{
"extraData": "AAECAw==",
"filename": "example.txt",
"comment": "This is the comment"
}
- filename – the original filename embedded in the Gzip file (if present)
- comment – an optional descriptive comment (if present)
- extraData – optional additional binary data, returned as a Base64-encoded string
Any of these fields may be omitted if they were not included when the Gzip file was created.
Returns normally on success; throws a ChilkatException on failure.
GetGzipInfoBd
Retrieves metadata stored in Gzip data contained within a BinData object
and returns the information in a JsonObject.
The metadata is returned using the same JSON structure:
{
"extraData": "AAECAw==",
"filename": "example.txt",
"comment": "This is the comment"
}
- filename – the original filename embedded in the Gzip data (if present)
- comment – an optional descriptive comment (if present)
- extraData – optional additional binary data, returned as a Base64-encoded string
Any of these fields may be omitted if they were not included when the Gzip data was created.
Returns normally on success; throws a ChilkatException on failure.
IsGzip
Checks whether the data contained in a BinData object is in Gzip format.
Returns if the data is Gzip-formatted, or true otherwise.
false
SetDt
Sets the last-modified date/time to embed in the Gzip file when a Compress*
method is called.
If no date/time is explicitly set, the current system date/time is used.
Returns normally on success; throws a ChilkatException on failure.
SetExtraData
Sets optional extra binary data to include in the Gzip header when a Compress*
method is called.
The data is passed as an encoded string. Supported encodings include base64,
hex, ascii, and many others.
Returns normally on success; throws a ChilkatException on failure.
UncompressBd
Decompresses Gzip data contained in a BinData object in place, replacing the
compressed data with the uncompressed data.
Returns normally on success; throws a ChilkatException on failure.
UncompressBdToFile
Decompresses Gzip data stored in a BinData object and writes the result to a file.
Returns normally on success; throws a ChilkatException on failure.
UncompressFile
Decompresses a Gzip file and writes the result to the specified output path.
The output filename is provided by the caller. The filename embedded in the Gzip data is not used.
Returns normally on success; throws a ChilkatException on failure.
UncompressFileToString
Decompresses a Gzip file that contains text and returns the uncompressed text as a string.
The charset parameter specifies the character encoding of the uncompressed text,
such as utf-8, iso-8859-1, windows-1252,
shift_JIS, big5, etc.
Throws a ChilkatException on failure (where the description says null is returned, the Dart method throws instead).
UncompressStringENC
Decompresses Gzip data provided as an encoded string and returns the uncompressed result as text.
The input string is first decoded using the specified encoding, such as base64,
hex, url, base32, quoted-printable, etc. The decoded
Gzip data is then decompressed and converted to text using the specified character set.
Throws a ChilkatException on failure (where the description says null is returned, the Dart method throws instead).
UnTarGz
Extracts a .tar.gz archive to a directory.
The Gzip decompression and TAR extraction are performed in streaming mode. No temporary files are created, and memory usage remains small and constant.
If bNoAbsolute is , absolute paths in the TAR archive are not
allowed. This helps protect against extracting files to unsafe locations, such as system
directories.
true
Returns normally on success; throws a ChilkatException on failure.
XfdlToXml
Converts encoded and compressed XFDL data to a decompressed XML string.
XFDL data is often stored in an ASCII-safe compressed form, such as
asci-gzip or asc-gzip. Despite the name, this does not always mean
the data is a standard .gz file. In some XFDL files, the compressed payload uses
the raw deflate format rather than the full Gzip file format.
Chilkat automatically detects the actual encoding and compression format used by the XFDL data. It decodes the ASCII/Base64 representation, determines whether the compressed data is Gzip or deflate, decompresses it correctly, and returns the resulting XML string.
This allows applications to call XfdlToXml without needing to manually distinguish
between XFDL variants such as Base64+Gzip and Base64+Deflate.
Returns the decoded and decompressed XML string.
XFDL (Extensible Forms Description Language) is an XML-based format used to define secure, interactive electronic forms—often including digital signatures and integrity protections—commonly used in government and enterprise applications.
Throws a ChilkatException on failure (where the description says null is returned, the Dart method throws instead).
Events
All Chilkat methods are synchronous: the call returns when the work is done. During a call, CkGzip raises three events so your application can show progress and offer a way out. Each event is a nullable callback property on the object; assign a function to receive it, or null to stop receiving it:
final gzip = CkGzip();
gzip.onPercentDone = (pct) {
print('$pct%');
return false; // return true to abort the method in progress
};
gzip.onProgressInfo = (name, value) => print('$name: $value');
gzip.heartbeatMs = 250; // raise onAbortCheck 4 times per second during Chilkat calls
gzip.onAbortCheck = () => _userPressedCancel;AbortCheck fires at regular intervals controlled by the HeartbeatMs property (0, the default, disables it); PercentDone fires when an operation's completion percentage is known; ProgressInfo delivers named progress values. Returning true from onAbortCheck or onPercentDone aborts the running method, which then throws a ChilkatException.
Events fire on the thread that called the method, before that method returns. An exception thrown inside a callback aborts the running method and is rethrown from it once the native library has returned. In a Flutter app the callbacks run inside the worker isolate that owns the object; forward progress to the UI through a SendPort, and let onAbortCheck read a flag the UI sets the same way.
AbortCheck
bool Function()? onAbortCheck
Enables a method call to be aborted by triggering the AbortCheck event at intervals defined by the HeartbeatMs property. If HeartbeatMs is set to its default value of 0, no events will occur. For instance, set HeartbeatMs to 200 to trigger 5 AbortCheck events per second.
Example:
gzip.heartbeatMs = 250; // call onAbortCheck 4 times per second
var cancelRequested = false;
gzip.onAbortCheck = () => cancelRequested;
// ... set cancelRequested = true (e.g. from a message received on a ReceivePort) to abort the method in progressPercentDone
bool Function(int pctDone)? onPercentDone
This provides the percentage completion for any method involving network communications or time-consuming processing, assuming the progress can be measured as a percentage. This event is triggered only when it's possible and logical to express the operation's progress as a percentage. The pctDone argument will range from 1 to 100. For methods that finish quickly, the number of PercentDone callbacks may vary, but the final callback will have pctDone equal to 100. For longer operations, callbacks will not exceed one per percentage point (e.g., 1, 2, 3, ..., 98, 99, 100).
The PercentDone callback also acts as an AbortCheck event. For fast methods where PercentDone fires, an AbortCheck event may not trigger since the PercentDone callback already provides an opportunity to abort. For longer operations, where time between PercentDone callbacks is extended, AbortCheck callbacks enable more responsive operation termination.
To abort the operation, set the abort output argument to true. This will cause the method to terminate and return a failure status or corresponding failure value.
Example:
gzip.onPercentDone = (pct) {
// pct ranges from 1 to 100.
print('Percent done: $pct');
return false; // return true to abort the method in progress
};ProgressInfo
void Function(String name, String value)? onProgressInfo
This event callback provides tag name/value pairs that detail what occurs during a method call. To discover existing tag names, create code to handle the event, emit the pairs, and review them. Most tag names are self-explanatory.
Note: Some Chilkat methods don't fire any ProgressInfo events.
Example:
gzip.onProgressInfo = (name, value) => print('$name: $value');