![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java JavaScript 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) Compressing StringBuilder Data Using CompressSb (Single Call and Chunked)See more Compression ExamplesThis example demonstrates how to compress text stored in aStringBuilder using the CompressSb method in two ways:
The example shows how compressed output is appended to a Key Points
integer li_rc integer li_Success oleobject loo_Compress oleobject loo_Sb oleobject loo_BdCompressed string ls_CompressedBase64 oleobject loo_BdChunkedOut oleobject loo_SbPart string ls_ChunkedBase64 oleobject loo_SbDecompressed li_Success = 0 // This example assumes the Chilkat API has already been unlocked. // See Global Unlock Sample for sample code. loo_Compress = create oleobject li_rc = loo_Compress.ConnectToNewObject("Chilkat.Compression") if li_rc < 0 then destroy loo_Compress MessageBox("Error","Connecting to COM object failed") return end if loo_Compress.Algorithm = "zlib" // ================================================================ // 1) Single-call compression (entire data in one call) // ================================================================ loo_Sb = create oleobject li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder") loo_Sb.Append("The quick brown fox jumps over the lazy dog. ") loo_Sb.Append("This is a simple example using CompressSb.") loo_BdCompressed = create oleobject li_rc = loo_BdCompressed.ConnectToNewObject("Chilkat.BinData") // When both FirstChunk and LastChunk are true (the defaults), // the entire compression happens in a single call. loo_Compress.FirstChunk = 1 loo_Compress.LastChunk = 1 li_Success = loo_Compress.CompressSb(loo_Sb,loo_BdCompressed) if li_Success = 0 then Write-Debug loo_Compress.LastErrorText destroy loo_Compress destroy loo_Sb destroy loo_BdCompressed return end if ls_CompressedBase64 = loo_BdCompressed.GetEncoded("base64") Write-Debug "Single-call compressed (base64):" Write-Debug ls_CompressedBase64 // ================================================================ // 2) Chunked compression using FirstChunk / LastChunk // ================================================================ loo_BdChunkedOut = create oleobject li_rc = loo_BdChunkedOut.ConnectToNewObject("Chilkat.BinData") // First chunk loo_Compress.FirstChunk = 1 loo_Compress.LastChunk = 0 loo_SbPart = create oleobject li_rc = loo_SbPart.ConnectToNewObject("Chilkat.StringBuilder") loo_SbPart.Append("The quick brown fox ") li_Success = loo_Compress.CompressSb(loo_SbPart,loo_BdChunkedOut) if li_Success = 0 then Write-Debug loo_Compress.LastErrorText destroy loo_Compress destroy loo_Sb destroy loo_BdCompressed destroy loo_BdChunkedOut destroy loo_SbPart return end if // Middle chunk loo_Compress.FirstChunk = 0 loo_Compress.LastChunk = 0 loo_SbPart.Clear() loo_SbPart.Append("jumps over the lazy dog. ") li_Success = loo_Compress.CompressSb(loo_SbPart,loo_BdChunkedOut) if li_Success = 0 then Write-Debug loo_Compress.LastErrorText destroy loo_Compress destroy loo_Sb destroy loo_BdCompressed destroy loo_BdChunkedOut destroy loo_SbPart return end if // Final chunk loo_Compress.FirstChunk = 0 loo_Compress.LastChunk = 1 loo_SbPart.Clear() loo_SbPart.Append("This is a chunked CompressSb example.") li_Success = loo_Compress.CompressSb(loo_SbPart,loo_BdChunkedOut) if li_Success = 0 then Write-Debug loo_Compress.LastErrorText destroy loo_Compress destroy loo_Sb destroy loo_BdCompressed destroy loo_BdChunkedOut destroy loo_SbPart return end if ls_ChunkedBase64 = loo_BdChunkedOut.GetEncoded("base64") Write-Debug "Chunked compressed (base64):" Write-Debug ls_ChunkedBase64 // ================================================================ // 3) Decompress to verify correctness // ================================================================ loo_SbDecompressed = create oleobject li_rc = loo_SbDecompressed.ConnectToNewObject("Chilkat.StringBuilder") // Decompress in a single call (entire data already assembled) loo_Compress.FirstChunk = 1 loo_Compress.LastChunk = 1 li_Success = loo_Compress.DecompressSb(loo_BdChunkedOut,loo_SbDecompressed) if li_Success = 0 then Write-Debug loo_Compress.LastErrorText destroy loo_Compress destroy loo_Sb destroy loo_BdCompressed destroy loo_BdChunkedOut destroy loo_SbPart destroy loo_SbDecompressed return end if Write-Debug "Decompressed text:" Write-Debug loo_SbDecompressed.GetAsString() destroy loo_Compress destroy loo_Sb destroy loo_BdCompressed destroy loo_BdChunkedOut destroy loo_SbPart destroy loo_SbDecompressed |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.