The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.

LuaZip
Reading files inside zip files

Example

Suppose we have the following file hierarchy:

/a
    /b
        c.zip
/a2
    b2.ext2
/a3.ext3
/luazip.zip
  • c.zip contains the file 'd.txt'
  • b2.ext2 is a zip file containing the file 'c2/d2.txt'
  • a3.ext3 is a zip file containing the file 'b3/c3/d3.txt'
  • luazip.zip contains the files 'luazip.h', 'luazip.c', 'Makefile', 'README'
Below is a small sample code displaying the basic use of the library.
require "zip"

local zfile, err = zip.open('luazip.zip')

-- print the filenames of the files inside the zip
for file in zfile:files() do
	print(file.filename)
end

-- open README and print it
local f1, err = zfile:open('README')
local s1 = f1:read("*a")
print(s1)

f1:close()
zfile:close()

-- open d.txt inside c.zip
local d, err = zip.openfile('a/b/c/d.txt')
assert(d, err)
d:close()

-- open d2.txt inside b2.ext2
local d2, err = zip.openfile('a2/b2/c2/d2.txt', "ext2")
assert(d2, err)
d2:close()

-- open d3.txt inside a3.ext3
local d3, err = zip.openfile('a3/b3/c3/d3.txt', {"ext2", "ext3"})
assert(d3, err)
d3:close()

Valid XHTML 1.0!

$Id: examples.html,v 1.4 2006/03/23 20:45:21 carregal Exp $

These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.