Sample code for 30+ languages & platforms
Delphi DLL

Decompress Gzip Data from BinData Directly to a File

See more Gzip Examples

This example demonstrates how to use the UncompressBdToFile method to decompress Gzip data stored in a BinData object and write the uncompressed output directly to a file.

The compressed .gz data is first loaded into memory using a BinData object. The UncompressBdToFile method then decompresses the data and writes the result directly to the specified file, without modifying the contents of the BinData object.

This approach is useful when you want to extract compressed data to disk without performing an in-place transformation or managing intermediate buffers.

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, BinData, Gzip;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
gzip: HCkGzip;
bd: HCkBinData;

begin
success := False;

// This example demonstrates how to decompress Gzip data stored in a BinData object
// and write the uncompressed output directly to a file.

gzip := CkGzip_Create();
bd := CkBinData_Create();

// Load a .gz file into BinData:
success := CkBinData_LoadFile(bd,'example.txt.gz');
if (success = False) then
  begin
    Memo1.Lines.Add(CkBinData__lastErrorText(bd));
    Exit;
  end;

Memo1.Lines.Add('Loaded Gzip data into memory.');

// Uncompress the Gzip data and write directly to a file:
success := CkGzip_UncompressBdToFile(gzip,bd,'example.txt');
if (success = False) then
  begin
    Memo1.Lines.Add(CkGzip__lastErrorText(gzip));
    Exit;
  end;

Memo1.Lines.Add('File successfully uncompressed to example.txt');

CkGzip_Dispose(gzip);
CkBinData_Dispose(bd);

end;