Sample code for 30+ languages & platforms
AutoIt

File Read Blocks

Demonstrates how to read a file in fixed-size blocks (except for the very last block).

Chilkat AutoIt Downloads

AutoIt
Local $bSuccess = False

;  Demonstrates how to read a file in blocks,
;  which can be useful when uploading to cloud storage
;  services such as Azure, S3, Google, etc.

;  For this example, we're simply writing the blocks
;  to an output file, and then checking to see if the
;  resulting file contents equals the original file contents.

Local $oDataBlock

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

Local $srcPath = "qa_data/xml/hamlet.xml"
Local $sDestPath = "qa_output/hamletOut.xml"

$bSuccess = $oFacSrc.OpenForRead($srcPath)
$bSuccess = $oFacDest.OpenForWrite($sDestPath)
;  Assuming success for the example..

;  How many 1024-byte blocks?  (Including 1 for the last partial block)
Local $iNumBlocks = $oFacSrc.GetNumBlocks(1024)

Local $i = 0
While ($i < $iNumBlocks)
    $oDataBlock = $oFacSrc.ReadBlock($i,1024)
    If ($oFacSrc.LastMethodSuccess <> True) Then
        ConsoleWrite($oFacSrc.LastErrorText & @CRLF)
        Exit
    EndIf

    $bSuccess = $oFacDest.FileWrite($oDataBlock)
    If ($bSuccess <> True) Then
        ConsoleWrite($oFacDest.LastErrorText & @CRLF)
        Exit
    EndIf

    $i = $i + 1
Wend

$oFacSrc.FileClose 
$oFacDest.FileClose 

Local $bEqual = $oFacSrc.FileContentsEqual($srcPath,$sDestPath)
If ($bEqual <> True) Then
    ConsoleWrite("Something went wrong!" & @CRLF)
    Exit
EndIf

ConsoleWrite("File successfully copied by blocks." & @CRLF)