Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

Transition from BeginCompressStringENC to FirstChunk/LastChunk

Provides instructions for replacing deprecated BeginCompressStringENC method calls with using FirstChunk/LastChunk properties.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oSbCompressedBase64
LOCAL oCompress
LOCAL oSbIndex
LOCAL i
LOCAL cOriginalText
LOCAL oBdCompressed
LOCAL oSbUncompressedChunk

nSuccess := 0

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

oSbCompressedBase64 := CreateObject("Chilkat.StringBuilder")

oCompress := CreateObject("Chilkat.Compression")
oCompress:Algorithm := "deflate"
oCompress:Charset := "utf-8"
oCompress:EncodingMode := "base64"

oSbIndex := CreateObject("Chilkat.StringBuilder")

//  ----------------------------------------------------------------------------------
//  This is the deprecated way of compressing in chunks using Begin/More/End methods..
//  ----------------------------------------------------------------------------------

FOR i := 0 TO 24
    //  Note: It is possible (and normal) for a BeginCompress* or MoreCompress* method to return
    //  an empty string (or 0 bytes).  When this happens, the input data is not lost.  It will be flushed
    //  in a subsequent call.
    oSbIndex:Clear()
    oSbIndex:AppendInt(i)
    IF (i == 0)
        oSbCompressedBase64:Append(oCompress:BeginCompressStringENC(oSbIndex:GetAsString()))
    ELSE
        oSbCompressedBase64:Append(oCompress:MoreCompressStringENC(oSbIndex:GetAsString()))
    ENDIF

    oSbCompressedBase64:Append(oCompress:MoreCompressStringENC(": This is a line of data to be compressed..." + Chr(13) + Chr(10)))
NEXT

//  Flush any remaining output.
oSbCompressedBase64:Append(oCompress:EndCompressStringENC())

? "The base64 encoded compressed text:"
? oSbCompressedBase64:GetAsString()

//  Decompress in one call:
cOriginalText := oCompress:DecompressStringENC(oSbCompressedBase64:GetAsString())
? cOriginalText

//  ----------------------------------------------------------------------------------
//  This is new way of compressing in chunks using FirstChunk and LastChunk properties
//  ----------------------------------------------------------------------------------

oSbCompressedBase64:Clear()

oCompress:FirstChunk := 1
oCompress:LastChunk := 0

oBdCompressed := CreateObject("Chilkat.BinData")
oSbUncompressedChunk := CreateObject("Chilkat.StringBuilder")

FOR i := 0 TO 24
    IF (i == 24)
        oCompress:LastChunk := 1
    ENDIF

    oSbUncompressedChunk:Clear()
    oSbUncompressedChunk:AppendInt(i)
    oSbUncompressedChunk:Append(": This is a line of data to be compressed..." + Chr(13) + Chr(10))

    oCompress:CompressSb(oSbUncompressedChunk, oBdCompressed)

    oCompress:FirstChunk := 0
NEXT

? "The base64 encoded compressed text:"
? oBdCompressed:GetEncoded("base64")

//  Decompress in one call:
cOriginalText := oCompress:DecompressStringENC(oBdCompressed:GetEncoded("base64"))
? cOriginalText

oSbCompressedBase64:destroy()
oCompress:destroy()
oSbIndex:destroy()
oBdCompressed:destroy()
oSbUncompressedChunk:destroy()