![]() |
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
(VB.NET) 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
Dim success As Boolean = False ' This example assumes the Chilkat API has already been unlocked. ' See Global Unlock Sample for sample code. Dim compress As New Chilkat.Compression compress.Algorithm = "zlib" ' ================================================================ ' 1) Single-call compression (entire data in one call) ' ================================================================ Dim sb As New Chilkat.StringBuilder sb.Append("The quick brown fox jumps over the lazy dog. ") sb.Append("This is a simple example using CompressSb.") Dim bdCompressed As New Chilkat.BinData ' When both FirstChunk and LastChunk are true (the defaults), ' the entire compression happens in a single call. compress.FirstChunk = True compress.LastChunk = True success = compress.CompressSb(sb,bdCompressed) If (success = False) Then Debug.WriteLine(compress.LastErrorText) Exit Sub End If Dim compressedBase64 As String = bdCompressed.GetEncoded("base64") Debug.WriteLine("Single-call compressed (base64):") Debug.WriteLine(compressedBase64) ' ================================================================ ' 2) Chunked compression using FirstChunk / LastChunk ' ================================================================ Dim bdChunkedOut As New Chilkat.BinData ' First chunk compress.FirstChunk = True compress.LastChunk = False Dim sbPart As New Chilkat.StringBuilder sbPart.Append("The quick brown fox ") success = compress.CompressSb(sbPart,bdChunkedOut) If (success = False) Then Debug.WriteLine(compress.LastErrorText) Exit Sub End If ' Middle chunk compress.FirstChunk = False compress.LastChunk = False sbPart.Clear() sbPart.Append("jumps over the lazy dog. ") success = compress.CompressSb(sbPart,bdChunkedOut) If (success = False) Then Debug.WriteLine(compress.LastErrorText) Exit Sub End If ' Final chunk compress.FirstChunk = False compress.LastChunk = True sbPart.Clear() sbPart.Append("This is a chunked CompressSb example.") success = compress.CompressSb(sbPart,bdChunkedOut) If (success = False) Then Debug.WriteLine(compress.LastErrorText) Exit Sub End If Dim chunkedBase64 As String = bdChunkedOut.GetEncoded("base64") Debug.WriteLine("Chunked compressed (base64):") Debug.WriteLine(chunkedBase64) ' ================================================================ ' 3) Decompress to verify correctness ' ================================================================ Dim sbDecompressed As New Chilkat.StringBuilder ' Decompress in a single call (entire data already assembled) compress.FirstChunk = True compress.LastChunk = True success = compress.DecompressSb(bdChunkedOut,sbDecompressed) If (success = False) Then Debug.WriteLine(compress.LastErrorText) Exit Sub End If Debug.WriteLine("Decompressed text:") Debug.WriteLine(sbDecompressed.GetAsString()) |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.