Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Compress Bytes
See more Compression Examples
Demonstrates how to compress binary data.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.Compression,
Chilkat.FileAccess;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
fac: TFileAccess;
fileBytes: TBytes;
compress: TCompression;
compressedBytes: TBytes;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
fac := TFileAccess.Create;
fileBytes := fac.ReadEntireFile('qa_data/bmp/big.bmp');
if (fac.LastMethodSuccess <> True) then
begin
WriteLn(fac.LastErrorText);
Exit;
end;
compress := TCompression.Create;
compress.Algorithm := 'deflate';
compressedBytes := compress.CompressBytes(fileBytes);
if (compress.LastMethodSuccess <> True) then
begin
WriteLn(compress.LastErrorText);
Exit;
end;
success := fac.WriteEntireFile('qa_output/compressedBmp.dat',compressedBytes);
if (fac.LastMethodSuccess <> True) then
begin
WriteLn(fac.LastErrorText);
Exit;
end;
fac.Free;
compress.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.