Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Decode Base64 to Zip File

See more Base64 Examples

Shows how to decode a baes64 string that is the encoded representation of the bytes that make up a .zip archive. Decodes the base64 and writes the .zip file.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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.BinData;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  b64: string;
  zipData: TBinData;

begin
  success := False;

  b64 := 'UEsDBBQA ... AAALgQAAAAA';

  zipData := TBinData.Create;
  success := zipData.AppendEncoded(b64,'base64');
  success := zipData.WriteFile('qa_output/out.zip');
  if (success <> True) then
    begin
      WriteLn('failed to write Zip file.');
      Exit;
    end;


  zipData.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.