Dart Requires Chilkat v11.5.0+
Dart
Retrieve Metadata from Gzip Data in Memory (BinData)
This example demonstrates how to use the GetGzipInfoBd method to retrieve metadata from Gzip data stored in memory within a BinData object.
The Gzip data is first loaded into the BinData instance. The GetGzipInfoBd method then extracts any available metadata from the Gzip header, including the embedded filename, comment, and optional extra data.
The metadata is returned in a JsonObject. Because these fields are optional, the example checks for the existence of each JSON member using HasMember before retrieving its value.
Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example demonstrates how to retrieve metadata from Gzip data
// stored in a BinData object.
final gzip = CkGzip();
final bd = CkBinData();
final json = CkJsonObject();
// Load a Gzip file into BinData:
try {
bd.loadFile('example.txt.gz');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Get the metadata information from the in-memory Gzip data:
try {
gzip.getGzipInfoBd(bd, json);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Output the JSON containing metadata:
print('Gzip metadata JSON:');
print(json.emit());
// Access individual fields only if they exist:
if (json.hasMember('filename')) {
final filename = json.stringOf('filename');
print('Filename: $filename');
}
if (json.hasMember('comment')) {
final comment = json.stringOf('comment');
print('Comment: $comment');
}
if (json.hasMember('extraData')) {
final extraData = json.stringOf('extraData');
print('ExtraData (Base64): $extraData');
}
}