PowerBuilder
PowerBuilder
Gzip Compress In Memory and Base64 Encode
See more Gzip Examples
Demonstrates how to Gzip compress in-memory data and then encode the compressed data to base64.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Gzip
oleobject loo_FileData
string ls_StrBase64
string ls_StrBase64MultiLine
li_Success = 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loo_Gzip = create oleobject
li_rc = loo_Gzip.ConnectToNewObject("Chilkat.Gzip")
if li_rc < 0 then
destroy loo_Gzip
MessageBox("Error","Connecting to COM object failed")
return
end if
// This example will load a file into the fileData object.
// Your application might load fileData from other sources..
loo_FileData = create oleobject
li_rc = loo_FileData.ConnectToNewObject("Chilkat.BinData")
li_Success = loo_FileData.LoadFile("qa_data/xml/hamlet.xml")
if li_Success <> 1 then
Write-Debug "Failed to load file."
destroy loo_Gzip
destroy loo_FileData
return
end if
// In-place compress the contents of fileData
li_Success = loo_Gzip.CompressBd(loo_FileData)
if li_Success <> 1 then
Write-Debug loo_Gzip.LastErrorText
destroy loo_Gzip
destroy loo_FileData
return
end if
// Get the base64 encoded compressed data (in a single line).
ls_StrBase64 = loo_FileData.GetEncoded("base64")
Write-Debug ls_StrBase64
Write-Debug "--------"
// To get the base64 in multiple lines, as it might appear in MIME,
// use "base64-mime".
ls_StrBase64MultiLine = loo_FileData.GetEncoded("base64-mime")
Write-Debug ls_StrBase64MultiLine
destroy loo_Gzip
destroy loo_FileData