Xbase++ Requires Chilkat v11.0.0+
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oCrypt
LOCAL oZip
LOCAL oBd
LOCAL oFac
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oCrypt := CreateObject("Chilkat.Crypt2")
oZip := CreateObject("Chilkat.Zip")
nSuccess := oZip:NewZip("test.zip")
IF (nSuccess == 0)
? oZip:LastErrorText
oCrypt:destroy()
oZip:destroy()
RETURN
ENDIF
// Add the bytes 0x00 0x01 0x02 0x03 ... 0x0F as a file in the .zip
oBd := CreateObject("Chilkat.BinData")
oBd:AppendEncoded("000102030405060708090A0B0C0D0E0F", "hex")
oZip:AddBd("binaryData.dat", oBd)
// Add the string "Hello World!" to the .zip
oZip:AddString("helloWorld.txt", "Hello World!", "utf-8")
oZipFileInMemory := oZip:WriteToMemory()
// We could save these files to a file, and it is a valid .zip
oFac := CreateObject("Chilkat.FileAccess")
nSuccess := oFac:WriteEntireFile("test.zip", oZipFileInMemory)
IF (nSuccess == 0)
? oFac:LastErrorText
oCrypt:destroy()
oZip:destroy()
oBd:destroy()
oFac:destroy()
RETURN
ENDIF
? "Zip Created!"
oCrypt:destroy()
oZip:destroy()
oBd:destroy()
oFac:destroy()