(PureBasic) Ungzip Base64 String
Suppose you have a gzip in base64 representation that contains a text file, such as XML. This example shows how to decompress and access the string.
IncludeFile "CkGzip.pb"
IncludeFile "CkBinData.pb"
Procedure ChilkatExample()
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
gzip.i = CkGzip::ckCreate()
If gzip.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
gzipBase64.s = "H4sIAAAAAAAE ... X6aZjXO3EwAA"
bd.i = CkBinData::ckCreate()
If bd.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i = CkBinData::ckAppendEncoded(bd,gzipBase64,"base64")
success = CkGzip::ckUncompressBd(gzip,bd)
If success <> 1
Debug CkGzip::ckLastErrorText(gzip)
CkGzip::ckDispose(gzip)
CkBinData::ckDispose(bd)
ProcedureReturn
EndIf
strXml.s = CkBinData::ckGetString(bd,"utf-8")
Debug "XML:"
Debug strXml
CkGzip::ckDispose(gzip)
CkBinData::ckDispose(bd)
ProcedureReturn
EndProcedure
|