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) Compress Large Binary File in BlocksCompresses a large binary file in blocks. This example uses BeginCompressBytes, MoreCompressBytes, and EndCompressBytes.
load ./chilkat.dll # This example assumes the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set facSrc [new_CkFileAccess] set facDest [new_CkFileAccess] # Open a large binary file for reading. set success [CkFileAccess_OpenForRead $facSrc "qa_data/bmp/big.bmp"] if {$success != 1} then { puts [CkFileAccess_lastErrorText $facSrc] delete_CkFileAccess $facSrc delete_CkFileAccess $facDest exit } # If we compress in 64K chunks, find out how many blocks there will be. set blockSize 65536 set numBlocks [CkFileAccess_GetNumBlocks $facSrc $blockSize] # Open an output file for the compressed data. set success [CkFileAccess_OpenForWrite $facDest "qa_data/bmp/compressedBmp.dat"] if {$success != 1} then { puts [CkFileAccess_lastErrorText $facDest] delete_CkFileAccess $facSrc delete_CkFileAccess $facDest exit } set compress [new_CkCompression] CkCompression_put_Algorithm $compress "deflate" set fileBytes [new_CkByteData] set compressedBytes [new_CkByteData] set i 0 while {$i < $numBlocks} { set success [CkFileAccess_ReadBlock $facSrc $i $blockSize $fileBytes] if {$i == 0} then { set success [CkCompression_BeginCompressBytes $compress $fileBytes $compressedBytes] } else { set success [CkCompression_MoreCompressBytes $compress $fileBytes $compressedBytes] } CkFileAccess_FileWrite $facDest $compressedBytes set i [expr $i + 1] } # At the very end, flush any remaining compressed bytes, if any. set success [CkCompression_EndCompressBytes $compress $compressedBytes] CkFileAccess_FileWrite $facDest $compressedBytes CkFileAccess_FileClose $facSrc CkFileAccess_FileClose $facDest puts "Finished compressing file." delete_CkFileAccess $facSrc delete_CkFileAccess $facDest delete_CkCompression $compress delete_CkByteData $fileBytes delete_CkByteData $compressedBytes |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.