Sample code for 30+ languages & platforms
AutoIt

Compress Text Feed to Binary

See more Compression Examples

This example receives incoming text data in chunks, compresses as a stream, and accumulates the compressed binary data.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

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

$oBdCompressed = ObjCreate("Chilkat.BinData")

$oCompress = ObjCreate("Chilkat.Compression")
$oCompress.Algorithm = "deflate"
$oCompress.Charset = "utf-8"

$oSbUncompressedChunk = ObjCreate("Chilkat.StringBuilder")

$oCompress.FirstChunk = True
$oCompress.LastChunk = False

Local $i
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

; Show the compressed data in hex format:
ConsoleWrite("The hex encoded compressed text:" & @CRLF)
ConsoleWrite($oBdCompressed.GetEncoded("hex") & @CRLF)

; Now decompress in one call.  It is important to set both FirstChunk and LastChunk = True
$oBdDecompressed = ObjCreate("Chilkat.BinData")
$oCompress.FirstChunk = True
$oCompress.LastChunk = True
$bSuccess = $oCompress.DecompressBd2($oBdCompressed,$oBdDecompressed)
If ($bSuccess = False) Then
    ConsoleWrite($oCompress.LastErrorText & @CRLF)
    Exit
EndIf

Local $sOriginalText = $oBdDecompressed.GetString("utf-8")
ConsoleWrite($sOriginalText & @CRLF)