![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) File Read BlocksDemonstrates how to read a file in fixed-size blocks (except for the very last block).
; 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_9_5_0.FileAccess") $oFacDest = ObjCreate("Chilkat_9_5_0.FileAccess") Local $srcPath = "qa_data/xml/hamlet.xml" Local $sDestPath = "qa_output/hamletOut.xml" Local $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) |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.