Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Unzip an AES Encrypted Text File directly into a String Variable
See more Zip Examples
A common need is to unzip from an AES encrypted Zip archive directly into a string variable, such that the unencrypted file never resides on disk, even temporarily. This example shows how to do it.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.ZipEntry,
Chilkat.Zip;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
zip: TZip;
entry: TZipEntry;
lineEndingBehavior: Integer;
srcCharset: string;
xmlText: string;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
zip := TZip.Create;
// This example opens a WinZip-compatible AES encrypted
// .zip that contains a single file: hamlet.xml.
// It decrypts and unzips hamlet.xml directly into a string
// variable.
zip.SetPassword('secret');
success := zip.OpenZip('qa_data/hamlet.zip');
if (success = False) then
begin
WriteLn(zip.LastErrorText);
Exit;
end;
entry := TZipEntry.Create;
success := zip.EntryOf('hamlet.xml',entry);
if (success = False) then
begin
WriteLn(zip.LastErrorText);
Exit;
end;
// lineEndingBehavior:
// 0 = leave unchanged.
// 1 = convert all to bare LF's
// 2 = convert all to CRLF's
lineEndingBehavior := 0;
srcCharset := 'utf-8';
xmlText := entry.UnzipToString(lineEndingBehavior,srcCharset);
WriteLn(xmlText);
zip.Free;
entry.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.