![]() |
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
(Tcl) Compress Text Feed to BinaryThis example receives incoming text data in chunks, compresses as a stream, and accumulates the compressed binary data. Note: This example requires Chilkat v11.0.0 or greater.
load ./chilkat.dll set success 0 # This example assumes the Chilkat API to have been previously unlocked. # See Global Unlock Sample for sample code. set bdCompressed [new_CkBinData] set compress [new_CkCompression] CkCompression_put_Algorithm $compress "deflate" CkCompression_put_Charset $compress "utf-8" set sbUncompressedChunk [new_CkStringBuilder] CkCompression_put_FirstChunk $compress 1 CkCompression_put_LastChunk $compress 0 for {set i 0} {$i <= 24} {incr i} { if {$i == 24} then { CkCompression_put_LastChunk $compress 1 } CkStringBuilder_Clear $sbUncompressedChunk CkStringBuilder_AppendInt $sbUncompressedChunk $i CkStringBuilder_Append $sbUncompressedChunk ": This is a line of data to be compressed...\r\n" CkCompression_CompressSb $compress $sbUncompressedChunk $bdCompressed CkCompression_put_FirstChunk $compress 0 } # Show the compressed data in hex format: puts "The hex encoded compressed text:" puts [CkBinData_getEncoded $bdCompressed hex] # Now decompress in one call. It is important to set both FirstChunk and LastChunk = 1 set bdDecompressed [new_CkBinData] CkCompression_put_FirstChunk $compress 1 CkCompression_put_LastChunk $compress 1 set success [CkCompression_DecompressBd2 $compress $bdCompressed $bdDecompressed] if {$success == 0} then { puts [CkCompression_lastErrorText $compress] delete_CkBinData $bdCompressed delete_CkCompression $compress delete_CkStringBuilder $sbUncompressedChunk delete_CkBinData $bdDecompressed exit } set originalText [CkBinData_getString $bdDecompressed "utf-8"] puts "$originalText" delete_CkBinData $bdCompressed delete_CkCompression $compress delete_CkStringBuilder $sbUncompressedChunk delete_CkBinData $bdDecompressed |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.