![]() |
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
(PowerBuilder) Compress Large Binary File in BlocksCompresses a large binary file in blocks. Note: This example requires Chilkat v11.0.0 or greater.
integer li_rc integer li_Success oleobject loo_FacSrc oleobject loo_FacDest integer li_BlockSize integer li_NumBlocks oleobject loo_Compress integer i li_Success = 0 // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_FacSrc = create oleobject li_rc = loo_FacSrc.ConnectToNewObject("Chilkat.FileAccess") if li_rc < 0 then destroy loo_FacSrc MessageBox("Error","Connecting to COM object failed") return end if loo_FacDest = create oleobject li_rc = loo_FacDest.ConnectToNewObject("Chilkat.FileAccess") // Open a large binary file for reading. li_Success = loo_FacSrc.OpenForRead("qa_data/bmp/big.bmp") if li_Success = 0 then Write-Debug loo_FacSrc.LastErrorText destroy loo_FacSrc destroy loo_FacDest return end if // If we compress in 64K chunks, find out how many blocks there will be. li_BlockSize = 65536 li_NumBlocks = loo_FacSrc.GetNumBlocks(li_BlockSize) // Open an output file for the compressed data. li_Success = loo_FacDest.OpenForWrite("c:/temp/qa_output/compressedBmp.dat") if li_Success = 0 then Write-Debug loo_FacDest.LastErrorText destroy loo_FacSrc destroy loo_FacDest return end if loo_Compress = create oleobject li_rc = loo_Compress.ConnectToNewObject("Chilkat.Compression") loo_Compress.Algorithm = "deflate" // Assuming numBlocks > 1 loo_Compress.FirstChunk = 1 loo_Compress.LastChunk = 0 i = 0 do while i < li_NumBlocks loo_FileBytes = loo_FacSrc.ReadBlock(i,li_BlockSize) loo_CompressedBytes = loo_Compress.CompressBytes(loo_FileBytes) loo_FacDest.FileWrite(loo_CompressedBytes) i = i + 1 loo_Compress.FirstChunk = 0 if i = (li_NumBlocks - 1) then loo_Compress.LastChunk = 1 end if loop loo_FacSrc.FileClose() loo_FacDest.FileClose() Write-Debug "Finished compressing file." destroy loo_FacSrc destroy loo_FacDest destroy loo_Compress |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.