Sample code for 30+ languages & platforms
Delphi ActiveX

Deflate File

Demonstrates how to use the Deflate compression algorithm to compress a file. (The deflate compression algorithm is the most commonly used in the Zip archive file format.)

This code is capable of compressing any size file because the file data is compressed from input to output in a streaming mode. The output file contains only the deflated data (it is not a .zip, and there is no file structure or format).

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Integer;
compress: TChilkatCompression;

begin
success := 0;

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

compress := TChilkatCompression.Create(Self);

compress.Algorithm := 'deflate';

// Deflate this XML file:
success := compress.CompressFile('hamlet.xml','hamletDeflate.dat');
if (success <> 1) then
  begin
    Memo1.Lines.Add(compress.LastErrorText);
    Exit;
  end;

// Inflate back to the original:
success := compress.DecompressFile('hamletDeflate.dat','hamletInflated.xml');
if (success <> 1) then
  begin
    Memo1.Lines.Add(compress.LastErrorText);
    Exit;
  end;

Memo1.Lines.Add('Success!');
end;