Lianja
Lianja
Transition from BeginCompressStringENC to FirstChunk/LastChunk
Provides instructions for replacing deprecated BeginCompressStringENC method calls with using FirstChunk/LastChunk properties.Chilkat Lianja Downloads
llSuccess = .F.
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
loSbCompressedBase64 = createobject("CkStringBuilder")
loCompress = createobject("CkCompression")
loCompress.Algorithm = "deflate"
loCompress.Charset = "utf-8"
loCompress.EncodingMode = "base64"
loSbIndex = createobject("CkStringBuilder")
// ----------------------------------------------------------------------------------
// 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 = .T.
loCompress.LastChunk = .F.
loBdCompressed = createobject("CkBinData")
loSbUncompressedChunk = createobject("CkStringBuilder")
for i = 0 to 24
if (i = 24) then
loCompress.LastChunk = .T.
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 = .F.
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