Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) File Read BlocksDemonstrates how to read a file in fixed-size blocks (except for the very last block).
Use ChilkatAx-win32.pkg Procedure Test Variant hoDataBlock Handle hoFacSrc Handle hoFacDest String sSrcPath String sDestPath Boolean iSuccess Integer iNumBlocks Integer i Boolean iBEqual String sTemp1 Boolean bTemp1 // 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. Get Create (RefClass(cComCkFileAccess)) To hoFacSrc If (Not(IsComObjectCreated(hoFacSrc))) Begin Send CreateComObject of hoFacSrc End Get Create (RefClass(cComCkFileAccess)) To hoFacDest If (Not(IsComObjectCreated(hoFacDest))) Begin Send CreateComObject of hoFacDest End Move "qa_data/xml/hamlet.xml" To sSrcPath Move "qa_output/hamletOut.xml" To sDestPath Get ComOpenForRead Of hoFacSrc sSrcPath To iSuccess Get ComOpenForWrite Of hoFacDest sDestPath To iSuccess // Assuming success for the example.. // How many 1024-byte blocks? (Including 1 for the last partial block) Get ComGetNumBlocks Of hoFacSrc 1024 To iNumBlocks Move 0 To i While (i < iNumBlocks) Get ComReadBlock Of hoFacSrc i 1024 To hoDataBlock Get ComLastMethodSuccess Of hoFacSrc To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoFacSrc To sTemp1 Showln sTemp1 Procedure_Return End Get ComFileWrite Of hoFacDest vDataBlock To iSuccess If (iSuccess <> True) Begin Get ComLastErrorText Of hoFacDest To sTemp1 Showln sTemp1 Procedure_Return End Move (i + 1) To i Loop Send ComFileClose To hoFacSrc Send ComFileClose To hoFacDest Get ComFileContentsEqual Of hoFacSrc sSrcPath sDestPath To iBEqual If (iBEqual <> True) Begin Showln "Something went wrong!" Procedure_Return End Showln "File successfully copied by blocks." End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.