![]() |
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
(ASP) Streaming Deflate StringDemonstrates streaming string compression using the Deflate algorithm. Data may be compressed in chunks by initially calling one of the BeginCompress* methods, followed by 0 or more calls to a MoreCompress* method, and terminating with a call to an EndCompress* method. Likewise, data may be decompressed by calling a BeginDecompress* method, followed by 0 or more MoreDecompress* calls, and ending with an EndDecompress* method call. This example demonstrates string-to-string deflate compression and decompression in chunks. (The deflate algorithm is most commonly used by the .zip file format.)
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% set compress = Server.CreateObject("Chilkat_9_5_0.Compression") ' Any string argument automatically begins a 30-day trial. success = compress.UnlockComponent("30-day trial") If (success <> 1) Then Response.Write "<pre>" & Server.HTMLEncode( compress.LastErrorText) & "</pre>" End If compress.Algorithm = "deflate" compress.Charset = "ansi" compress.EncodingMode = "base64" ' Create a long string to compress. strData = "abcdefg1122334455667788" strData = strData & vbCrLf ' Note: BeginCompressStringENC may return a zero-length ' string. This is normal if the input is buffered and no ' compressed data is yet available. ' However, a null reference indicates an error -- which is ' generally only possible if the component was never unlocked. strCompressed = compress.BeginCompressStringENC(strData) ' Compress 100 more chunks of data. Each call to ' MoreCompressStringENC may or may not produce additional ' compressed output. For i = 0 To 99 strData = "abcdefg1122334455667788" strData = strData & vbCrLf strCompressed = strCompressed & compress.MoreCompressStringENC(strData) Next ' Finalize the compression with a single call to EndCompressStringENC: strCompressed = strCompressed & compress.EndCompressStringENC() ' Display the compressed string. ' The result will be: ' S0xKTklNSzc0NDIyNjYxMTU1MzM3t7Dg5UoclRiVGJUYlRiVGJUYlRiVGJUYchIA Response.Write "<pre>" & Server.HTMLEncode( strCompressed) & "</pre>" ' Decompress back to the original in a single call. strOriginal = compress.DecompressStringENC(strCompressed) ' Display the uncompressed original: Response.Write "<pre>" & Server.HTMLEncode( "--- Original ---") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( strOriginal) & "</pre>" ' Inflate in multiple calls. It doesn't matter how the ' compressed data is split -- it could be fed to the decompressor ' one char at a time if desired. chunk1 = "S0xKTklNSzc0ND" chunk2 = "Iy" chunk3 = "NjYxMTU1MzM3t7Dg5UoclRiV" chunk4 = "GJUYlRiVGJUYlRiVGJUYchIA" strOriginal = "" strOriginal = compress.BeginDecompressStringENC(chunk1) strOriginal = strOriginal & compress.MoreDecompressStringENC(chunk2) strOriginal = strOriginal & compress.MoreDecompressStringENC(chunk3) strOriginal = strOriginal & compress.MoreDecompressStringENC(chunk4) strOriginal = strOriginal & compress.EndDecompressStringENC() ' Display the uncompressed original after inflating in chunks: Response.Write "<pre>" & Server.HTMLEncode( "--- Original after Inflating from Chunks ---") & "</pre>" Response.Write "<pre>" & Server.HTMLEncode( strOriginal) & "</pre>" %> </body> </html> |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.