Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Decompress Bytes
See more Compression Examples
Demonstrates how to decompress 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;
compressedBytes: TBytes;
compress: TCompression;
decompressedBytes: TBytes;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
// See this example to compress bytes: Compress Bytes
fac := TFileAccess.Create;
compressedBytes := fac.ReadEntireFile('qa_data/compressed/compressedBmp.dat');
if (fac.LastMethodSuccess <> True) then
begin
WriteLn(fac.LastErrorText);
Exit;
end;
compress := TCompression.Create;
compress.Algorithm := 'deflate';
decompressedBytes := compress.DecompressBytes(compressedBytes);
if (compress.LastMethodSuccess <> True) then
begin
WriteLn(compress.LastErrorText);
Exit;
end;
success := fac.WriteEntireFile('qa_output/decompressed.bmp',decompressedBytes);
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.