(Unicode C) Base64 Encode a File
Unicode C to Base64 encode the contents of a file.
#include <C_CkFileAccessW.h>
void ChilkatSample(void)
{
HCkFileAccessW fac;
const wchar_t *strBase64;
BOOL success;
// Get the contents of a file into a base64 encoded string:
fac = CkFileAccessW_Create();
strBase64 = CkFileAccessW_readBinaryToEncoded(fac,L"c:/data/something.pdf",L"base64");
if (CkFileAccessW_getLastMethodSuccess(fac) != TRUE) {
wprintf(L"%s\n",CkFileAccessW_lastErrorText(fac));
CkFileAccessW_Dispose(fac);
return;
}
// Now write the string to a file:
success = CkFileAccessW_WriteEntireTextFile(fac,L"c:/data/something_pdf_base64.txt",strBase64,L"us-ascii",FALSE);
if (success != TRUE) {
wprintf(L"%s\n",CkFileAccessW_lastErrorText(fac));
CkFileAccessW_Dispose(fac);
return;
}
wprintf(L"Success!\n");
CkFileAccessW_Dispose(fac);
}
|