![]() |
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) Replacment for Deprecated Crypt2 Compress FunctionsThe Chilkat Crypt2 compression functions are deprecated and will be removed. This example shows how to duplicate the functionality using the Chilkat Compression class.
IncludeFile "CkBinData.pb" IncludeFile "CkCompression.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkCrypt2.pb" Procedure ChilkatExample() crypt.i = CkCrypt2::ckCreate() If crypt.i = 0 Debug "Failed to create object." ProcedureReturn EndIf ; Create data to be compressed. sb.i = CkStringBuilder::ckCreate() If sb.i = 0 Debug "Failed to create object." ProcedureReturn EndIf i.i = 0 While i < 25 CkStringBuilder::ckAppend(sb,"Hello World, this is a test." + Chr(13) + Chr(10)) i = i + 1 Wend ; Bzip2 compress the utf-8 byte representation of the string and return the compressed data as base64. CkCrypt2::setCkCharset(crypt, "utf-8") CkCrypt2::setCkEncodingMode(crypt, "base64") compressedStr.s = CkCrypt2::ckCompressStringENC(crypt,CkStringBuilder::ckGetAsString(sb)) Debug compressedStr ; Result: 4aeUs+4CAABCWmgzMUFZJlNZZ6znBgAAfNeAABJABQBAAIAmZJwAIABwUNNMAAUqoekYjMp4ixF1FlFxF8i5i1FvFwizF9iwi9RdxaizF7RZi6i0ixF3Fui/i7kinChIM9ZzgwA= ; The result contains an 8-byte header composed of a 4-byte magic number (0xB394A7E1) and a 4-byte length. ; Do the following to BZip2 decompress using Chilkat Compression bd.i = CkBinData::ckCreate() If bd.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkBinData::ckAppendEncoded(bd,compressedStr,"base64") ; Remove the 8-byte header. CkBinData::ckRemoveChunk(bd,0,8) ; Decompress compress.i = CkCompression::ckCreate() If compress.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkCompression::setCkAlgorithm(compress, "bzip2") CkCompression::ckDecompressBd(compress,bd) ; Get the decompressed string. decompressedStr.s = CkBinData::ckGetString(bd,"utf-8") Debug decompressedStr CkCrypt2::ckDispose(crypt) CkStringBuilder::ckDispose(sb) CkBinData::ckDispose(bd) CkCompression::ckDispose(compress) ProcedureReturn EndProcedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.