Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Check if a File is in Gzip Format
See more Gzip Examples
This example demonstrates how to use the ExamineFile method to determine whether a file is in Gzip format.
The method inspects the contents of the specified file and returns true if the file is recognized as a valid Gzip file, or false if it is not. This is useful for validating input files before attempting to decompress them.
If the method fails (for example, if the file does not exist or cannot be accessed), the CHECK_SUCCESS macro reports the error.
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
gzip: TGzip;
filePath: string;
isGzip: Boolean;
begin
// This example demonstrates how to determine if a file is in Gzip format.
gzip := TGzip.Create;
// The file to examine:
filePath := 'test.gz';
// Check if the file is a valid Gzip file:
isGzip := gzip.ExamineFile(filePath);
if (isGzip = True) then
begin
WriteLn('The file is a valid Gzip file.');
end
else
begin
WriteLn('The file isnot a Gzip file.');
end;
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.