![]() |
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
(PureBasic) Compress String Feed to Base64This example receives incoming text data in chunks, compresses as a stream, and accumulates the compressed data in base64. 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. sbCompressedBase64.i = CkStringBuilder::ckCreate() If sbCompressedBase64.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") CkCompression::setCkEncodingMode(compress, "base64") CkCompression::setCkFirstChunk(compress, 1) CkCompression::setCkLastChunk(compress, 0) bdCompressed.i = CkBinData::ckCreate() If bdCompressed.i = 0 Debug "Failed to create object." ProcedureReturn EndIf sbUncompressedChunk.i = CkStringBuilder::ckCreate() If sbUncompressedChunk.i = 0 Debug "Failed to create object." ProcedureReturn EndIf 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 Debug "The base64 encoded compressed text:" Debug CkBinData::ckGetEncoded(bdCompressed,"base64") ; Decompress in one call: originalText.s = CkCompression::ckDecompressStringENC(compress,CkBinData::ckGetEncoded(bdCompressed,"base64")) Debug originalText CkStringBuilder::ckDispose(sbCompressedBase64) CkCompression::ckDispose(compress) CkBinData::ckDispose(bdCompressed) CkStringBuilder::ckDispose(sbUncompressedChunk) ProcedureReturn EndProcedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.