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

Unzip Encrypted Text into a String Variable

See more Zip Examples

Demonstrates how to open an encrypted .zip archive and unzip a text file directly into a string variable.

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 zip = chilkat.Zip.new()

-- Set the password required for decrypting.
zip.decrypt_password = "myPassword"

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

-- Locate the file within the Zip to be unzipped into a string variable:
local entry = chilkat.ZipEntry.new()
success = zip:entry_matching("*.csv", entry)
if not success then
    print(zip.last_error_text)
    return
end

-- lineEndingBehavior:
-- 0 = leave unchanged.
-- 1 = convert all to bare LF's
-- 2 = convert all to CRLF's
local lineEndingBehavior = 0
local srcCharset = "utf-8"

local strCsv = entry:unzip_to_string(lineEndingBehavior, srcCharset)
print(strCsv)