Sample code for 30+ languages & platforms
Lua 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 Lua Downloads

Lua
local chilkat = require("chilkat")

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

local crypt = chilkat.Crypt2.new()
local zip = chilkat.Zip.new()

local success = zip:new_zip("test.zip")
if not success then
    print(zip.last_error_text)
    return
end

-- Add the bytes 0x00 0x01 0x02 0x03 ... 0x0F as a file in the .zip
local bd = chilkat.BinData.new()
bd:append_encoded("000102030405060708090A0B0C0D0E0F", "hex")
zip:add_bd("binaryData.dat", bd)

-- Add the string "Hello World!" to the .zip
zip:add_string("helloWorld.txt", "Hello World!", "utf-8")

zipFileInMemory = ERROR: Method not in Chilkat for Lua: Zip.WriteToMemory
zip:ERROR()

-- We could save these files to a file, and it is a valid .zip
local fac = chilkat.FileAccess.new()
success = ERROR: Method not in Chilkat for Lua: FileAccess.WriteEntireFile
fac:ERROR()
if not success then
    print(fac.last_error_text)
    return
end

print("Zip Created!")