![]() |
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
(Classic ASP) 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
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% success = 0 ' This example assumes the Chilkat API has already been unlocked. ' See Global Unlock Sample for sample code. set compress = Server.CreateObject("Chilkat.Compression") compress.Algorithm = "zlib" ' ================================================================ ' 1) Single-call compression (entire data in one call) ' ================================================================ set sb = Server.CreateObject("Chilkat.StringBuilder") success = sb.Append("The quick brown fox jumps over the lazy dog. ") success = sb.Append("This is a simple example using CompressSb.") set bdCompressed = Server.CreateObject("Chilkat.BinData") ' When both FirstChunk and LastChunk are true (the defaults), ' the entire compression happens in a single call. compress.FirstChunk = 1 compress.LastChunk = 1 success = compress.CompressSb(sb,bdCompressed) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( compress.LastErrorText) & "</pre>" Response.End End If compressedBase64 = bdCompressed.GetEncoded("base64") Response.Write "<pre>" & Server.HTMLEncode( "Single-call compressed (base64):") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( compressedBase64) & "</pre>" ' ================================================================ ' 2) Chunked compression using FirstChunk / LastChunk ' ================================================================ set bdChunkedOut = Server.CreateObject("Chilkat.BinData") ' First chunk compress.FirstChunk = 1 compress.LastChunk = 0 set sbPart = Server.CreateObject("Chilkat.StringBuilder") success = sbPart.Append("The quick brown fox ") success = compress.CompressSb(sbPart,bdChunkedOut) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( compress.LastErrorText) & "</pre>" Response.End End If ' Middle chunk compress.FirstChunk = 0 compress.LastChunk = 0 sbPart.Clear success = sbPart.Append("jumps over the lazy dog. ") success = compress.CompressSb(sbPart,bdChunkedOut) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( compress.LastErrorText) & "</pre>" Response.End End If ' Final chunk compress.FirstChunk = 0 compress.LastChunk = 1 sbPart.Clear success = sbPart.Append("This is a chunked CompressSb example.") success = compress.CompressSb(sbPart,bdChunkedOut) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( compress.LastErrorText) & "</pre>" Response.End End If chunkedBase64 = bdChunkedOut.GetEncoded("base64") Response.Write "<pre>" & Server.HTMLEncode( "Chunked compressed (base64):") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( chunkedBase64) & "</pre>" ' ================================================================ ' 3) Decompress to verify correctness ' ================================================================ set sbDecompressed = Server.CreateObject("Chilkat.StringBuilder") ' Decompress in a single call (entire data already assembled) compress.FirstChunk = 1 compress.LastChunk = 1 success = compress.DecompressSb(bdChunkedOut,sbDecompressed) If (success = 0) Then Response.Write "<pre>" & Server.HTMLEncode( compress.LastErrorText) & "</pre>" Response.End End If Response.Write "<pre>" & Server.HTMLEncode( "Decompressed text:") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( sbDecompressed.GetAsString()) & "</pre>" %> </body> </html> |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.