Sample code for 30+ languages & platforms
Lua

Download a Zip from a URL and OpenBd. (No .zip file is created)

See more Zip Examples

Demonstrates how to download a .zip from a URL, opens the Zip, and gets the contents of a file. No file is ever written.

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 http = chilkat.Http.new()

local bd = chilkat.BinData.new()

-- This URL is valid and can be tested...
local success = http:quick_get_bd("https://chilkatdownload.com/example_data/hamlet.zip", bd)
if not http.last_method_success then
    print(http.last_error_text)
    return
end

local zip = chilkat.Zip.new()

-- Open the zip from the bytes contained in bd.
success = zip:open_bd(bd)
if not success then
    print(zip.last_error_text)
    return
end

-- Get the entry for the file we want..
local entry = chilkat.ZipEntry.new()
success = zip:entry_of("hamlet.xml", entry)
if not success then
    print(zip.last_error_text)
    return
end

-- Convert all line endings to CRLF (if needed)
local lineEndingBehavior = 2
local xmlStr = entry:unzip_to_string(lineEndingBehavior, "utf-8")
if not entry.last_method_success then
    print(entry.last_error_text)
    return
end

-- The XML in this case is about 274K, so let's just examine the last 20 lines...
local sb = chilkat.StringBuilder.new()
sb:append(xmlStr)

print(sb:last_n_lines(20, true))