PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Zip
string ls_Base64Data
li_Success = 0
loo_Zip = create oleobject
li_rc = loo_Zip.ConnectToNewObject("Chilkat.Zip")
if li_rc < 0 then
destroy loo_Zip
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Zip.NewZip("encodedData.zip")
if li_Success = 0 then
Write-Debug loo_Zip.LastErrorText
destroy loo_Zip
return
end if
// Base64 for the text: "Hello World!"
ls_Base64Data = "SGVsbG8gV29ybGQh"
// Add the decoded bytes as "hello.txt" within the ZIP archive.
li_Success = loo_Zip.AddEncoded("hello.txt","base64",ls_Base64Data)
if li_Success = 0 then
Write-Debug loo_Zip.LastErrorText
destroy loo_Zip
return
end if
// Write the ZIP archive to disk and close it.
li_Success = loo_Zip.WriteZipAndClose()
if li_Success = 0 then
Write-Debug loo_Zip.LastErrorText
destroy loo_Zip
return
end if
Write-Debug "ZIP archive created successfully."
destroy loo_Zip