Delphi DLL
Delphi DLL
Retrieve Metadata from a Gzip File
See more Gzip Examples
This example demonstrates how to use the GetGzipInfo method to retrieve metadata embedded within a Gzip file.
The method reads the Gzip header and extracts any available metadata, including the embedded filename, comment, and optional extra data. The extracted information 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. This avoids attempting to access values that may not be present.
Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, JsonObject, Gzip;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
gzip: HCkGzip;
json: HCkJsonObject;
gzPath: PWideChar;
filename: PWideChar;
comment: PWideChar;
extraData: PWideChar;
begin
success := False;
// This example demonstrates how to retrieve metadata embedded in a Gzip file.
gzip := CkGzip_Create();
json := CkJsonObject_Create();
// The Gzip file to examine:
gzPath := 'example.txt.gz';
// Get the metadata information:
success := CkGzip_GetGzipInfo(gzip,gzPath,json);
if (success = False) then
begin
Memo1.Lines.Add(CkGzip__lastErrorText(gzip));
Exit;
end;
// Output the JSON containing metadata:
Memo1.Lines.Add('Gzip metadata JSON:');
Memo1.Lines.Add(CkJsonObject__emit(json));
// Access individual fields only if they exist:
if (CkJsonObject_HasMember(json,'filename') = True) then
begin
filename := CkJsonObject__stringOf(json,'filename');
Memo1.Lines.Add('Filename: ' + filename);
end;
if (CkJsonObject_HasMember(json,'comment') = True) then
begin
comment := CkJsonObject__stringOf(json,'comment');
Memo1.Lines.Add('Comment: ' + comment);
end;
if (CkJsonObject_HasMember(json,'extraData') = True) then
begin
extraData := CkJsonObject__stringOf(json,'extraData');
Memo1.Lines.Add('ExtraData (Base64): ' + extraData);
end;
CkGzip_Dispose(gzip);
CkJsonObject_Dispose(json);
end;