(Unicode C) Unzip Text File to String
Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to a string variable.
#include <C_CkZipW.h>
#include <C_CkZipEntryW.h>
void ChilkatSample(void)
{
HCkZipW zip;
BOOL success;
HCkZipEntryW entry;
const wchar_t *fileContents;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
zip = CkZipW_Create();
success = CkZipW_OpenZip(zip,L"qa_data/zips/EC16100.zip");
if (success != TRUE) {
wprintf(L"%s\n",CkZipW_lastErrorText(zip));
CkZipW_Dispose(zip);
return;
}
// Get the 1st file in the .zip
entry = CkZipW_GetEntryByIndex(zip,0);
if (CkZipW_getLastMethodSuccess(zip) != TRUE) {
wprintf(L"No files in this zip.\n");
CkZipW_Dispose(zip);
return;
}
fileContents = CkZipEntryW_unzipToString(entry,0,L"utf-8");
wprintf(L"%s\n",fileContents);
CkZipEntryW_Dispose(entry);
CkZipW_Dispose(zip);
}
|