![]() |
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
(Unicode 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_CkBinDataW.h> #include <C_CkCompressionW.h> #include <C_CkByteData.h> void ChilkatSample(void) { BOOL success; HCkBinDataW binData; int i; HCkCompressionW compress; HCkByteData uncompressedBytes; const wchar_t *compressedBase64; const wchar_t *compressedHex; HCkBinDataW 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 = CkBinDataW_Create(); for (i = 1; i <= 16; i++) { CkBinDataW_AppendEncoded(binData,L"000102030405060708090A0B0C0D0E0F",L"hex"); } compress = CkCompressionW_Create(); CkCompressionW_putAlgorithm(compress,L"deflate"); CkCompressionW_putEncodingMode(compress,L"base64"); uncompressedBytes = CkByteData_Create(); success = CkBinDataW_GetBinary(binData,uncompressedBytes); // Compress and return the compressed bytes in base64 format. compressedBase64 = CkCompressionW_compressBytesENC(compress,uncompressedBytes); wprintf(L"compressed and base64 encoded: %s\n",compressedBase64); // Compress and return in hex format: CkCompressionW_putEncodingMode(compress,L"hex"); compressedHex = CkCompressionW_compressBytesENC(compress,uncompressedBytes); wprintf(L"compressed and hex encoded: %s\n",compressedHex); // Now decompress.. binData2 = CkBinDataW_Create(); // Decompress the base64.. CkCompressionW_putEncodingMode(compress,L"base64"); success = CkCompressionW_DecompressBytesENC(compress,compressedBase64,uncompressedBytes); CkBinDataW_AppendBinary(binData2,uncompressedBytes); // Show the uncompressed bytes in hex format: wprintf(L"%s\n",CkBinDataW_getEncoded(binData2,L"hex")); wprintf(L"--\n"); // Decompress the hex.. CkCompressionW_putEncodingMode(compress,L"hex"); success = CkCompressionW_DecompressBytesENC(compress,compressedHex,uncompressedBytes); CkBinDataW_Clear(binData2); CkBinDataW_AppendBinary(binData2,uncompressedBytes); // Show the uncompressed bytes in hex format: wprintf(L"%s\n",CkBinDataW_getEncoded(binData2,L"hex")); wprintf(L"--\n"); CkBinDataW_Dispose(binData); CkCompressionW_Dispose(compress); CkByteData_Dispose(uncompressedBytes); CkBinDataW_Dispose(binData2); } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.