Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v11.0.0+

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 PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Crypt
oleobject loo_Zip
oleobject loo_Bd
oleobject loo_Fac

li_Success = 0

//  This example requires the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

loo_Crypt = create oleobject
li_rc = loo_Crypt.ConnectToNewObject("Chilkat.Crypt2")
if li_rc < 0 then
    destroy loo_Crypt
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_Zip = create oleobject
li_rc = loo_Zip.ConnectToNewObject("Chilkat.Zip")

li_Success = loo_Zip.NewZip("test.zip")
if li_Success = 0 then
    Write-Debug loo_Zip.LastErrorText
    destroy loo_Crypt
    destroy loo_Zip
    return
end if

//  Add the bytes 0x00 0x01 0x02 0x03 ... 0x0F as a file in the .zip
loo_Bd = create oleobject
li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData")

loo_Bd.AppendEncoded("000102030405060708090A0B0C0D0E0F","hex")
loo_Zip.AddBd("binaryData.dat",loo_Bd)

//  Add the string "Hello World!" to the .zip
loo_Zip.AddString("helloWorld.txt","Hello World!","utf-8")

loo_ZipFileInMemory = loo_Zip.WriteToMemory()

//  We could save these files to a file, and it is a valid .zip
loo_Fac = create oleobject
li_rc = loo_Fac.ConnectToNewObject("Chilkat.FileAccess")

li_Success = loo_Fac.WriteEntireFile("test.zip",loo_ZipFileInMemory)
if li_Success = 0 then
    Write-Debug loo_Fac.LastErrorText
    destroy loo_Crypt
    destroy loo_Zip
    destroy loo_Bd
    destroy loo_Fac
    return
end if

Write-Debug "Zip Created!"


destroy loo_Crypt
destroy loo_Zip
destroy loo_Bd
destroy loo_Fac