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
(PowerBuilder) Compress Large Binary File in BlocksCompresses a large binary file in blocks. This example uses BeginCompressBytes, MoreCompressBytes, and EndCompressBytes.
integer li_rc oleobject loo_FacSrc oleobject loo_FacDest integer li_Success integer li_BlockSize integer li_NumBlocks oleobject loo_Compress integer i // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. loo_FacSrc = create oleobject // Use "Chilkat_9_5_0.FileAccess" for versions of Chilkat < 10.0.0 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 // Use "Chilkat_9_5_0.FileAccess" for versions of Chilkat < 10.0.0 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 <> 1 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("qa_data/bmp/compressedBmp.dat") if li_Success <> 1 then Write-Debug loo_FacDest.LastErrorText destroy loo_FacSrc destroy loo_FacDest return end if loo_Compress = create oleobject // Use "Chilkat_9_5_0.Compression" for versions of Chilkat < 10.0.0 li_rc = loo_Compress.ConnectToNewObject("Chilkat.Compression") loo_Compress.Algorithm = "deflate" i = 0 do while i < li_NumBlocks loo_FileBytes = loo_FacSrc.ReadBlock(i,li_BlockSize) if i = 0 then loo_CompressedBytes = loo_Compress.BeginCompressBytes(loo_FileBytes) else loo_CompressedBytes = loo_Compress.MoreCompressBytes(loo_FileBytes) end if loo_FacDest.FileWrite(loo_CompressedBytes) i = i + 1 loop // At the very end, flush any remaining compressed bytes, if any. loo_CompressedBytes = loo_Compress.EndCompressBytes() loo_FacDest.FileWrite(loo_CompressedBytes) loo_FacSrc.FileClose() loo_FacDest.FileClose() Write-Debug "Finished compressing file." destroy loo_FacSrc destroy loo_FacDest destroy loo_Compress |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.