![]() |
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
(PureBasic) 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.
IncludeFile "CkBinData.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkCompression.pb" Procedure ChilkatExample() success.i = 0 ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. bdCompressed.i = CkBinData::ckCreate() If bdCompressed.i = 0 Debug "Failed to create object." ProcedureReturn EndIf compress.i = CkCompression::ckCreate() If compress.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkCompression::setCkAlgorithm(compress, "deflate") CkCompression::setCkCharset(compress, "utf-8") sbUncompressedChunk.i = CkStringBuilder::ckCreate() If sbUncompressedChunk.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkCompression::setCkFirstChunk(compress, 1) CkCompression::setCkLastChunk(compress, 0) i.i For i = 0 To 24 If i = 24 CkCompression::setCkLastChunk(compress, 1) EndIf CkStringBuilder::ckClear(sbUncompressedChunk) CkStringBuilder::ckAppendInt(sbUncompressedChunk,i) CkStringBuilder::ckAppend(sbUncompressedChunk,": This is a line of data to be compressed..." + Chr(13) + Chr(10)) CkCompression::ckCompressSb(compress,sbUncompressedChunk,bdCompressed) CkCompression::setCkFirstChunk(compress, 0) Next ; Show the compressed data in hex format: Debug "The hex encoded compressed text:" Debug CkBinData::ckGetEncoded(bdCompressed,"hex") ; Now decompress in one call. It is important to set both FirstChunk and LastChunk = 1 bdDecompressed.i = CkBinData::ckCreate() If bdDecompressed.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkCompression::setCkFirstChunk(compress, 1) CkCompression::setCkLastChunk(compress, 1) success = CkCompression::ckDecompressBd2(compress,bdCompressed,bdDecompressed) If success = 0 Debug CkCompression::ckLastErrorText(compress) CkBinData::ckDispose(bdCompressed) CkCompression::ckDispose(compress) CkStringBuilder::ckDispose(sbUncompressedChunk) CkBinData::ckDispose(bdDecompressed) ProcedureReturn EndIf originalText.s = CkBinData::ckGetString(bdDecompressed,"utf-8") Debug originalText CkBinData::ckDispose(bdCompressed) CkCompression::ckDispose(compress) CkStringBuilder::ckDispose(sbUncompressedChunk) CkBinData::ckDispose(bdDecompressed) ProcedureReturn EndProcedure |
||||
© 2000-2026 Chilkat Software, Inc. All Rights Reserved.