Delphi DLL
Delphi DLL
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 Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Gzip, BinData, JsonObject;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
gzip: HCkGzip;
bd: HCkBinData;
json: HCkJsonObject;
filename: PWideChar;
comment: PWideChar;
extraData: PWideChar;
begin
success := False;
// This example demonstrates how to retrieve metadata from Gzip data
// stored in a BinData object.
gzip := CkGzip_Create();
bd := CkBinData_Create();
json := CkJsonObject_Create();
// Load a Gzip file into BinData:
success := CkBinData_LoadFile(bd,'example.txt.gz');
if (success = False) then
begin
Memo1.Lines.Add(CkBinData__lastErrorText(bd));
Exit;
end;
// Get the metadata information from the in-memory Gzip data:
success := CkGzip_GetGzipInfoBd(gzip,bd,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);
CkBinData_Dispose(bd);
CkJsonObject_Dispose(json);
end;