Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(C) Compress Bytes to Base64 (or any other encoding)Compresses bytes to base64 or any other encoding. Also decompress to return the original.
#include <C_CkBinData.h> #include <C_CkCompression.h> #include <C_CkByteData.h> void ChilkatSample(void) { BOOL success; HCkBinData binData; int i; HCkCompression compress; HCkByteData uncompressedBytes; const char *compressedBase64; const char *compressedHex; HCkBinData binData2; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // First create some binary data to compress. binData = CkBinData_Create(); for (i = 1; i <= 16; i++) { CkBinData_AppendEncoded(binData,"000102030405060708090A0B0C0D0E0F","hex"); } compress = CkCompression_Create(); CkCompression_putAlgorithm(compress,"deflate"); CkCompression_putEncodingMode(compress,"base64"); uncompressedBytes = CkByteData_Create(); success = CkBinData_GetBinary(binData,uncompressedBytes); // Compress and return the compressed bytes in base64 format. compressedBase64 = CkCompression_compressBytesENC(compress,uncompressedBytes); printf("compressed and base64 encoded: %s\n",compressedBase64); // Compress and return in hex format: CkCompression_putEncodingMode(compress,"hex"); compressedHex = CkCompression_compressBytesENC(compress,uncompressedBytes); printf("compressed and hex encoded: %s\n",compressedHex); // Now decompress.. binData2 = CkBinData_Create(); // Decompress the base64.. CkCompression_putEncodingMode(compress,"base64"); success = CkCompression_DecompressBytesENC(compress,compressedBase64,uncompressedBytes); CkBinData_AppendBinary(binData2,uncompressedBytes); // Show the uncompressed bytes in hex format: printf("%s\n",CkBinData_getEncoded(binData2,"hex")); printf("--\n"); // Decompress the hex.. CkCompression_putEncodingMode(compress,"hex"); success = CkCompression_DecompressBytesENC(compress,compressedHex,uncompressedBytes); CkBinData_Clear(binData2); CkBinData_AppendBinary(binData2,uncompressedBytes); // Show the uncompressed bytes in hex format: printf("%s\n",CkBinData_getEncoded(binData2,"hex")); printf("--\n"); CkBinData_Dispose(binData); CkCompression_Dispose(compress); CkByteData_Dispose(uncompressedBytes); CkBinData_Dispose(binData2); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.