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

Compress Large Binary File in Blocks

See more Compression Examples

Compresses a large binary file in blocks.

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.

$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

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

Local $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." & @CRLF)