Unicode C++
Unicode C++
Create a Zip Entirely in Memory
See more Zip Examples
Demonstrates how to create a .zip from in-memory byte data and strings, and to write the .zip to an in-memory image.Chilkat Unicode C++ Downloads
#include <CkCrypt2W.h>
#include <CkZipW.h>
#include <CkBinDataW.h>
#include <CkByteData.h>
#include <CkFileAccessW.h>
void ChilkatSample(void)
{
bool success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkCrypt2W crypt;
CkZipW zip;
success = zip.NewZip(L"test.zip");
if (success == false) {
wprintf(L"%s\n",zip.lastErrorText());
return;
}
// Add the bytes 0x00 0x01 0x02 0x03 ... 0x0F as a file in the .zip
CkBinDataW bd;
bd.AppendEncoded(L"000102030405060708090A0B0C0D0E0F",L"hex");
zip.AddBd(L"binaryData.dat",bd);
// Add the string "Hello World!" to the .zip
zip.AddString(L"helloWorld.txt",L"Hello World!",L"utf-8");
CkByteData zipFileInMemory;
success = zip.WriteToMemory(zipFileInMemory);
// We could save these files to a file, and it is a valid .zip
CkFileAccessW fac;
success = fac.WriteEntireFile(L"test.zip",zipFileInMemory);
if (success == false) {
wprintf(L"%s\n",fac.lastErrorText());
return;
}
wprintf(L"Zip Created!\n");
}