Unicode C
Unicode C
Zip Append StringBuilder
See more Zip Examples
Append the contents of a Chilkat StringBuilder object to a .zip.Chilkat Unicode C Downloads
#include <C_CkZipW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
BOOL success;
HCkZipW zip;
const wchar_t *zipPath;
HCkStringBuilderW sb;
int i;
HCkZipW zip2;
const wchar_t *zipPath2;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
zip = CkZipW_Create();
zipPath = L"c:/temp/qa_output/out.zip";
CkZipW_NewZip(zip,zipPath);
sb = CkStringBuilderW_Create();
i = 0;
while (i < 100) {
CkStringBuilderW_AppendLine(sb,L"This is a test",TRUE);
i = i + 1;
}
CkZipW_AddSb(zip,L"this_is_a_test.txt",sb,L"utf-8");
success = CkZipW_WriteZipAndClose(zip);
if (success == FALSE) {
wprintf(L"%s\n",CkZipW_lastErrorText(zip));
CkZipW_Dispose(zip);
CkStringBuilderW_Dispose(sb);
return;
}
wprintf(L"Success 1.\n");
// Perhaps you want to add a file to an existing .zip
zip2 = CkZipW_Create();
// Open the .zip we just wrote..
success = CkZipW_OpenZip(zip2,zipPath);
CkStringBuilderW_Clear(sb);
i = 0;
while (i < 100) {
CkStringBuilderW_AppendLine(sb,L"This is a test 2",TRUE);
i = i + 1;
}
CkZipW_AddSb(zip2,L"this_is_a_test_2.txt",sb,L"utf-8");
zipPath2 = L"c:/temp/qa_output/out2.zip";
CkZipW_putFileName(zip2,zipPath2);
success = CkZipW_WriteZipAndClose(zip2);
if (success == FALSE) {
wprintf(L"%s\n",CkZipW_lastErrorText(zip2));
CkZipW_Dispose(zip);
CkStringBuilderW_Dispose(sb);
CkZipW_Dispose(zip2);
return;
}
wprintf(L"Success 2.\n");
CkZipW_Dispose(zip);
CkStringBuilderW_Dispose(sb);
CkZipW_Dispose(zip2);
}