Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Gzip a File
See more Gzip Examples
Demonstrates how to create a .gz (gzipped file).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.Gzip;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
gzip: TGzip;
embeddedExtractPath: string;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
gzip := TGzip.Create;
// This will create a .gz such that when ungzipped by a tool such as 7-Zip,
// it will create "qa_data/hamlet.xml".
success := gzip.CompressFile('qa_data/hamlet.xml','qa_output/hamlet.xml.gz');
if (success = False) then
begin
WriteLn(gzip.LastErrorText);
Exit;
end;
// Call CompressFile2 to explicitly specify the ungzip path
// For example, this will create a .gz such that when ungzipped by a tool such as 7-Zip,
// it will create "hamlet.xml".
embeddedExtractPath := 'hamlet.xml';
success := gzip.CompressFile2('qa_data/hamlet.xml',embeddedExtractPath,'qa_output/hamlet2.xml.gz');
if (success = False) then
begin
WriteLn(gzip.LastErrorText);
Exit;
end;
WriteLn('Success.');
gzip.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.