(Unicode C) Convert any File to Base64 (and back)
Demonstrates how to get the contents of any file as a base64 string, and then write it back.
#include <C_CkBinDataW.h>
void ChilkatSample(void)
{
HCkBinDataW bd;
BOOL success;
const wchar_t *b64Str;
HCkBinDataW bd2;
bd = CkBinDataW_Create();
// This example will load a PDF and return it as a base64 string.
success = CkBinDataW_LoadFile(bd,L"qa_data/pdf/helloWorld.pdf");
if (success != TRUE) {
wprintf(L"Failed to load file.\n");
CkBinDataW_Dispose(bd);
return;
}
b64Str = CkBinDataW_getEncoded(bd,L"base64");
wprintf(L"%s\n",b64Str);
// Now write the base64 string back to the binary PDF file:
bd2 = CkBinDataW_Create();
success = CkBinDataW_AppendEncoded(bd2,b64Str,L"base64");
success = CkBinDataW_WriteFile(bd2,L"qa_output/helloWorld.pdf");
CkBinDataW_Dispose(bd);
CkBinDataW_Dispose(bd2);
}
|