AutoIt
AutoIt
Transition from BeginCompressStringENC to FirstChunk/LastChunk
Provides instructions for replacing deprecated BeginCompressStringENC method calls with using FirstChunk/LastChunk properties.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oSbCompressedBase64 = ObjCreate("Chilkat.StringBuilder")
$oCompress = ObjCreate("Chilkat.Compression")
$oCompress.Algorithm = "deflate"
$oCompress.Charset = "utf-8"
$oCompress.EncodingMode = "base64"
$oSbIndex = ObjCreate("Chilkat.StringBuilder")
; ----------------------------------------------------------------------------------
; This is the deprecated way of compressing in chunks using Begin/More/End methods..
; ----------------------------------------------------------------------------------
Local $i
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) Then
$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..." & @CRLF))
Next
; Flush any remaining output.
$oSbCompressedBase64.Append($oCompress.EndCompressStringENC())
ConsoleWrite("The base64 encoded compressed text:" & @CRLF)
ConsoleWrite($oSbCompressedBase64.GetAsString() & @CRLF)
; Decompress in one call:
Local $sOriginalText = $oCompress.DecompressStringENC($oSbCompressedBase64.GetAsString())
ConsoleWrite($sOriginalText & @CRLF)
; ----------------------------------------------------------------------------------
; This is new way of compressing in chunks using FirstChunk and LastChunk properties
; ----------------------------------------------------------------------------------
$oSbCompressedBase64.Clear
$oCompress.FirstChunk = True
$oCompress.LastChunk = False
$oBdCompressed = ObjCreate("Chilkat.BinData")
$oSbUncompressedChunk = ObjCreate("Chilkat.StringBuilder")
For $i = 0 To 24
If ($i = 24) Then
$oCompress.LastChunk = True
EndIf
$oSbUncompressedChunk.Clear
$oSbUncompressedChunk.AppendInt($i)
$oSbUncompressedChunk.Append(": This is a line of data to be compressed..." & @CRLF)
$oCompress.CompressSb($oSbUncompressedChunk,$oBdCompressed)
$oCompress.FirstChunk = False
Next
ConsoleWrite("The base64 encoded compressed text:" & @CRLF)
ConsoleWrite($oBdCompressed.GetEncoded("base64") & @CRLF)
; Decompress in one call:
$sOriginalText = $oCompress.DecompressStringENC($oBdCompressed.GetEncoded("base64"))
ConsoleWrite($sOriginalText & @CRLF)