AutoIt
AutoIt
Compress and Decompress a String
See more Compression Examples
Demonstrates how to compress and decompress a string.Chilkat AutoIt Downloads
Local $bSuccess = False
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
$oSb = ObjCreate("Chilkat.StringBuilder")
Local $i
For $i = 1 To 20
$oSb.Append("This is the original uncompressed string." & @CRLF)
Next
$oCompress = ObjCreate("Chilkat.Compression")
$oCompress.Algorithm = "deflate"
; Indicate that the utf-8 byte representation of the string should be compressed.
$oCompress.Charset = "utf-8"
Local $oCompressedBytes
$oCompressedBytes = $oCompress.CompressString($oSb.GetAsString())
; If the compressed data is desired in string format, then get the base64 representation of the bytes.
$oCompress.EncodingMode = "base64"
Local $sCompressedBase64 = $oCompress.CompressStringENC($oSb.GetAsString())
ConsoleWrite("Compressed Bytes as Base64: " & $sCompressedBase64 & @CRLF)
; Now decompress...
Local $sDecompressedString = $oCompress.DecompressString($oCompressedBytes)
ConsoleWrite("The original string after decompressing from binary compressed data:" & @CRLF)
ConsoleWrite($sDecompressedString & @CRLF)
; To decompress from Base64...
$oCompress.EncodingMode = "base64"
$sDecompressedString = $oCompress.DecompressStringENC($sCompressedBase64)
ConsoleWrite("The original string after decompressing from Base64:" & @CRLF)
ConsoleWrite($sDecompressedString & @CRLF)