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
(Tcl) File Read BlocksDemonstrates how to read a file in fixed-size blocks (except for the very last block).
load ./chilkat.dll # 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. set dataBlock [new_CkByteData] set facSrc [new_CkFileAccess] set facDest [new_CkFileAccess] set srcPath "qa_data/xml/hamlet.xml" set destPath "qa_output/hamletOut.xml" set success [CkFileAccess_OpenForRead $facSrc $srcPath] set success [CkFileAccess_OpenForWrite $facDest $destPath] # Assuming success for the example.. # How many 1024-byte blocks? (Including 1 for the last partial block) set numBlocks [CkFileAccess_GetNumBlocks $facSrc 1024] set i 0 while {$i < $numBlocks} { set success [CkFileAccess_ReadBlock $facSrc $i 1024 $dataBlock] if {[CkFileAccess_get_LastMethodSuccess $facSrc] != 1} then { puts [CkFileAccess_lastErrorText $facSrc] delete_CkByteData $dataBlock delete_CkFileAccess $facSrc delete_CkFileAccess $facDest exit } set success [CkFileAccess_FileWrite $facDest $dataBlock] if {$success != 1} then { puts [CkFileAccess_lastErrorText $facDest] delete_CkByteData $dataBlock delete_CkFileAccess $facSrc delete_CkFileAccess $facDest exit } set i [expr $i + 1] } CkFileAccess_FileClose $facSrc CkFileAccess_FileClose $facDest set bEqual [CkFileAccess_FileContentsEqual $facSrc $srcPath $destPath] if {$bEqual != 1} then { puts "Something went wrong!" delete_CkByteData $dataBlock delete_CkFileAccess $facSrc delete_CkFileAccess $facDest exit } puts "File successfully copied by blocks." delete_CkByteData $dataBlock delete_CkFileAccess $facSrc delete_CkFileAccess $facDest |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.