Sample code for 30+ languages & platforms
AutoIt Requires Chilkat v11.0.0+

Transition from Compression.BeginCompressBytes to FirstChunk/LastChunk

Provides instructions for replacing deprecated BeginCompressBytes method calls with using FirstChunk and LastChunk properties.

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

$oFacSrc = ObjCreate("Chilkat.FileAccess")
$oFacDest = ObjCreate("Chilkat.FileAccess")

;  Open a large binary file for reading.
$bSuccess = $oFacSrc.OpenForRead("qa_data/bmp/big.bmp")
If ($bSuccess = False) Then
    ConsoleWrite($oFacSrc.LastErrorText & @CRLF)
    Exit
EndIf

;  If we compress in 64K chunks, find out how many blocks there will be.
Local $iBlockSize = 65536
Local $iNumBlocks = $oFacSrc.GetNumBlocks($iBlockSize)

;  Open an output file for the compressed data.
$bSuccess = $oFacDest.OpenForWrite("c:/temp/qa_output/compressedBmp.dat")
If ($bSuccess = False) Then
    ConsoleWrite($oFacDest.LastErrorText & @CRLF)
    Exit
EndIf

$oCompress = ObjCreate("Chilkat.Compression")
$oCompress.Algorithm = "deflate"

Local $oFileBytes
Local $oCompressedBytes

;  ----------------------------------------------------------------------------------
;  This is the deprecated way of compressing in chunks using Begin/More/End methods..
;  ----------------------------------------------------------------------------------
Local $i = 0
While $i < $iNumBlocks
    $oFileBytes = $oFacSrc.ReadBlock($i,$iBlockSize)
    If ($i = 0) Then
        $oCompressedBytes = $oCompress.BeginCompressBytes($oFileBytes)
    Else
        $oCompressedBytes = $oCompress.MoreCompressBytes($oFileBytes)
    EndIf

    $oFacDest.FileWrite($oCompressedBytes)

    $i = $i + 1
Wend

;  At the very end, flush any remaining compressed bytes, if any.
$oCompressedBytes = $oCompress.EndCompressBytes()
$oFacDest.FileWrite($oCompressedBytes)

$oFacSrc.FileClose 
$oFacDest.FileClose 

ConsoleWrite("Finished compressing file." & @CRLF)

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

$bSuccess = $oFacSrc.OpenForRead("qa_data/bmp/big.bmp")
If ($bSuccess = False) Then
    ConsoleWrite($oFacSrc.LastErrorText & @CRLF)
    Exit
EndIf

$bSuccess = $oFacDest.OpenForWrite("c:/temp/qa_output/compressedBmp2.dat")
If ($bSuccess = False) Then
    ConsoleWrite($oFacDest.LastErrorText & @CRLF)
    Exit
EndIf

;  Assuming numBlocks > 1
$oCompress.FirstChunk = True
$oCompress.LastChunk = False

$i = 0
While $i < $iNumBlocks
    $oFileBytes = $oFacSrc.ReadBlock($i,$iBlockSize)
    $oCompressedBytes = $oCompress.CompressBytes($oFileBytes)

    $oFacDest.FileWrite($oCompressedBytes)

    $i = $i + 1

    $oCompress.FirstChunk = False
    If ($i = ($iNumBlocks - 1)) Then
        $oCompress.LastChunk = True
    EndIf

Wend

$oFacSrc.FileClose 
$oFacDest.FileClose 

ConsoleWrite("Finished compressing file 2." & @CRLF)