Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oGzip
LOCAL oFileData
LOCAL cStrBase64
LOCAL cStrBase64MultiLine

nSuccess := 0

//  This example assumes the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oGzip := CreateObject("Chilkat.Gzip")

//  This example will load a file into the fileData object.
//  Your application might load fileData from other sources..
oFileData := CreateObject("Chilkat.BinData")
nSuccess := oFileData:LoadFile("qa_data/xml/hamlet.xml")
IF (nSuccess != 1)
    ? "Failed to load file."
    oGzip:destroy()
    oFileData:destroy()
    RETURN
ENDIF

//  In-place compress the contents of fileData
nSuccess := oGzip:CompressBd(oFileData)
IF (nSuccess != 1)
    ? oGzip:LastErrorText
    oGzip:destroy()
    oFileData:destroy()
    RETURN
ENDIF

//  Get the base64 encoded compressed data (in a single line).
cStrBase64 := oFileData:GetEncoded("base64")
? cStrBase64
? "--------"

//  To get the base64 in multiple lines, as it might appear in MIME,
//  use "base64-mime".
cStrBase64MultiLine := oFileData:GetEncoded("base64-mime")
? cStrBase64MultiLine

oGzip:destroy()
oFileData:destroy()