Sample code for 30+ languages & platforms
Visual FoxPro

Transition from BeginCompressStringENC to FirstChunk/LastChunk

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

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loSbCompressedBase64
LOCAL loCompress
LOCAL loSbIndex
LOCAL i
LOCAL lcOriginalText
LOCAL loBdCompressed
LOCAL loSbUncompressedChunk

lnSuccess = 0

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

loSbCompressedBase64 = CreateObject('Chilkat.StringBuilder')

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

loSbIndex = 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.
    loSbIndex.Clear()
    loSbIndex.AppendInt(i)
    IF (i = 0) THEN
        loSbCompressedBase64.Append(loCompress.BeginCompressStringENC(loSbIndex.GetAsString()))
    ELSE
        loSbCompressedBase64.Append(loCompress.MoreCompressStringENC(loSbIndex.GetAsString()))
    ENDIF

    loSbCompressedBase64.Append(loCompress.MoreCompressStringENC(": This is a line of data to be compressed..." + CHR(13) + CHR(10)))
NEXT

* Flush any remaining output.
loSbCompressedBase64.Append(loCompress.EndCompressStringENC())

? "The base64 encoded compressed text:"
? loSbCompressedBase64.GetAsString()

* Decompress in one call:
lcOriginalText = loCompress.DecompressStringENC(loSbCompressedBase64.GetAsString())
? lcOriginalText

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

loSbCompressedBase64.Clear()

loCompress.FirstChunk = 1
loCompress.LastChunk = 0

loBdCompressed = CreateObject('Chilkat.BinData')
loSbUncompressedChunk = CreateObject('Chilkat.StringBuilder')

FOR i = 0 TO 24
    IF (i = 24) THEN
        loCompress.LastChunk = 1
    ENDIF

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

    loCompress.CompressSb(loSbUncompressedChunk,loBdCompressed)

    loCompress.FirstChunk = 0
NEXT

? "The base64 encoded compressed text:"
? loBdCompressed.GetEncoded("base64")

* Decompress in one call:
lcOriginalText = loCompress.DecompressStringENC(loBdCompressed.GetEncoded("base64"))
? lcOriginalText

RELEASE loSbCompressedBase64
RELEASE loCompress
RELEASE loSbIndex
RELEASE loBdCompressed
RELEASE loSbUncompressedChunk