(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_CkZip.h>
#include <C_CkZipEntry.h>
void ChilkatSample(void)
{
HCkZip zip;
BOOL success;
HCkZipEntry entry;
const char *fileContents;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
zip = CkZip_Create();
success = CkZip_OpenZip(zip,"qa_data/zips/EC16100.zip");
if (success != TRUE) {
printf("%s\n",CkZip_lastErrorText(zip));
CkZip_Dispose(zip);
return;
}
// Get the 1st file in the .zip
entry = CkZip_GetEntryByIndex(zip,0);
if (CkZip_getLastMethodSuccess(zip) != TRUE) {
printf("No files in this zip.\n");
CkZip_Dispose(zip);
return;
}
fileContents = CkZipEntry_unzipToString(entry,0,"utf-8");
printf("%s\n",fileContents);
CkZipEntry_Dispose(entry);
CkZip_Dispose(zip);
}
|