Lua Requires Chilkat v11.0.0+
Lua
Replace/Update a FIle in a .zip
See more Zip Examples
Demonstrates how to replace/update a file from a .zip. Note: This requires the entire .zip to be rewritten.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This requires the Chilkat Zip API to have been previously unlocked.
-- See Unlock Chilkat Zip for sample code.
-- First prepare a .zip and write it..
local zip = chilkat.Zip.new()
zip:new_zip("qa_output/abc.zip")
-- Add some files..
local charset = "utf-8"
zip:add_string("a.txt", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", charset)
zip:add_string("b.txt", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", charset)
zip:add_string("c.txt", "cccccccccccccccccccccccccccccccccccc", charset)
-- Write to qa_output/abc.zip
-- This .zip contains three files: a.txt, b.txt, and c.txt
local success = zip:write_zip_and_close()
-- -------------------------------------------------------------------
-- Open abc.zip, replace the content of the "b.txt" entry with something else, and re-write.
local zip2 = chilkat.Zip.new()
zip2:open_zip("qa_output/abc.zip")
local entry = chilkat.ZipEntry.new()
if zip2:entry_of("b.txt", entry) then
entry:replace_string("This is the new content. bbbbbbbbbbbbbbbbbbbbbb", "utf-8")
end
-- Write the modified .zip back to "abc.zip"
success = zip2:write_zip_and_close()
print("success.")