![]() |
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
(PowerBuilder) 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.
integer li_rc oleobject loo_Crypt oleobject loo_Sb integer i string ls_CompressedStr oleobject loo_Bd oleobject loo_Compress string ls_DecompressedStr loo_Crypt = create oleobject // Use "Chilkat_9_5_0.Crypt2" for versions of Chilkat < 10.0.0 li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2") if li_rc < 0 then destroy loo_Crypt MessageBox("Error","Connecting to COM object failed") return end if // Create data to be compressed. loo_Sb = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder") i = 0 do while i < 25 loo_Sb.Append("Hello World, this is a test.~r~n") i = i + 1 loop // Bzip2 compress the utf-8 byte representation of the string and return the compressed data as base64. loo_Crypt.Charset = "utf-8" loo_Crypt.EncodingMode = "base64" ls_CompressedStr = loo_Crypt.CompressStringENC(loo_Sb.GetAsString()) Write-Debug ls_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 loo_Bd = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData") loo_Bd.AppendEncoded(ls_CompressedStr,"base64") // Remove the 8-byte header. loo_Bd.RemoveChunk(0,8) // Decompress loo_Compress = create oleobject // Use "Chilkat_9_5_0.Compression" for versions of Chilkat < 10.0.0 li_rc = loo_Compress.ConnectToNewObject("Chilkat.Compression") loo_Compress.Algorithm = "bzip2" loo_Compress.DecompressBd(loo_Bd) // Get the decompressed string. ls_DecompressedStr = loo_Bd.GetString("utf-8") Write-Debug ls_DecompressedStr destroy loo_Crypt destroy loo_Sb destroy loo_Bd destroy loo_Compress |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.