![]() |
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) Compress Large Binary File in BlocksCompresses a large binary file in blocks. This example uses BeginCompressBytes, MoreCompressBytes, and EndCompressBytes.
; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. $oFacSrc = ObjCreate("Chilkat_9_5_0.FileAccess") $oFacDest = ObjCreate("Chilkat_9_5_0.FileAccess") ; Open a large binary file for reading. Local $bSuccess = $oFacSrc.OpenForRead("qa_data/bmp/big.bmp") If ($bSuccess <> True) Then ConsoleWrite($oFacSrc.LastErrorText & @CRLF) Exit EndIf ; If we compress in 64K chunks, find out how many blocks there will be. Local $iBlockSize = 65536 Local $iNumBlocks = $oFacSrc.GetNumBlocks($iBlockSize) ; Open an output file for the compressed data. $bSuccess = $oFacDest.OpenForWrite("qa_data/bmp/compressedBmp.dat") If ($bSuccess <> True) Then ConsoleWrite($oFacDest.LastErrorText & @CRLF) Exit EndIf $oCompress = ObjCreate("Chilkat_9_5_0.Compression") $oCompress.Algorithm = "deflate" Local $oFileBytes Local $oCompressedBytes Local $i = 0 While $i < $iNumBlocks $oFileBytes = $oFacSrc.ReadBlock($i,$iBlockSize) If ($i = 0) Then $oCompressedBytes = $oCompress.BeginCompressBytes($oFileBytes) Else $oCompressedBytes = $oCompress.MoreCompressBytes($oFileBytes) EndIf $oFacDest.FileWrite($oCompressedBytes) $i = $i + 1 Wend ; At the very end, flush any remaining compressed bytes, if any. $oCompressedBytes = $oCompress.EndCompressBytes() $oFacDest.FileWrite($oCompressedBytes) $oFacSrc.FileClose $oFacDest.FileClose ConsoleWrite("Finished compressing file." & @CRLF) |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.