Delphi DLL
Delphi DLL
Add Base64-Encoded Data to a ZIP Using AddEncoded
See more Zip Examples
This example demonstrates how to use the AddEncoded method to add encoded binary data as a file entry within a ZIP archive.
The example adds Base64-encoded data as a file named hello.txt within the ZIP archive. The Base64 text is automatically decoded to its original binary bytes before being stored in the ZIP.
This method is useful when binary data already exists in encoded textual form, such as Base64 or hex.
Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Zip;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
zip: HCkZip;
base64Data: PWideChar;
begin
success := False;
zip := CkZip_Create();
success := CkZip_NewZip(zip,'encodedData.zip');
if (success = False) then
begin
Memo1.Lines.Add(CkZip__lastErrorText(zip));
Exit;
end;
// Base64 for the text: "Hello World!"
base64Data := 'SGVsbG8gV29ybGQh';
// Add the decoded bytes as "hello.txt" within the ZIP archive.
success := CkZip_AddEncoded(zip,'hello.txt','base64',base64Data);
if (success = False) then
begin
Memo1.Lines.Add(CkZip__lastErrorText(zip));
Exit;
end;
// Write the ZIP archive to disk and close it.
success := CkZip_WriteZipAndClose(zip);
if (success = False) then
begin
Memo1.Lines.Add(CkZip__lastErrorText(zip));
Exit;
end;
Memo1.Lines.Add('ZIP archive created successfully.');
CkZip_Dispose(zip);
end;