Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Ungzip Base64 String
See more Gzip Examples
Suppose you have a gzip in base64 representation that contains a text file, such as XML. This example shows how to decompress and access the string.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.BinData,
Chilkat.Gzip;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
gzip: TGzip;
gzipBase64: string;
bd: TBinData;
strXml: string;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
gzip := TGzip.Create;
gzipBase64 := 'H4sIAAAAAAAE ... X6aZjXO3EwAA';
bd := TBinData.Create;
success := bd.AppendEncoded(gzipBase64,'base64');
success := gzip.UncompressBd(bd);
if (success <> True) then
begin
WriteLn(gzip.LastErrorText);
Exit;
end;
strXml := bd.GetString('utf-8');
WriteLn('XML:');
WriteLn(strXml);
gzip.Free;
bd.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.