| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" |
| 2 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
| 3 |
<html> |
| 4 |
<head> |
| 5 |
<title>LuaZip: Reading files inside zip files</title> |
| 6 |
<link rel="stylesheet" href="http://www.keplerproject.org/doc.css" type="text/css"/> |
| 7 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
| 8 |
</head> |
| 9 |
<body> |
| 10 |
|
| 11 |
<div id="container"> |
| 12 |
|
| 13 |
<div id="product"> |
| 14 |
<div id="product_logo"> |
| 15 |
<a href="http://www.keplerproject.org"><img alt="LuaZip logo" src="luazip-128.png"/></a> |
| 16 |
</div> |
| 17 |
<div id="product_name"><big><strong>LuaZip</strong></big></div> |
| 18 |
<div id="product_description">Reading files inside zip files</div> |
| 19 |
</div> |
| 20 |
|
| 21 |
<div id="main"> |
| 22 |
|
| 23 |
<div id="navigation"> |
| 24 |
<h1>LuaZip</h1> |
| 25 |
<ul> |
| 26 |
<li><a href="index.html">Home</a> |
| 27 |
<ul> |
| 28 |
<li><a href="index.html#overview">Overview</a></li> |
| 29 |
<li><a href="index.html#status">Status</a></li> |
| 30 |
<li><a href="index.html#download">Download</a></li> |
| 31 |
<li><a href="index.html#history">History</a></li> |
| 32 |
<li><a href="index.html#credits">Credits</a></li> |
| 33 |
<li><a href="index.html#contact">Contact</a></li> |
| 34 |
</ul> |
| 35 |
</li> |
| 36 |
<li><a href="manual.html">Manual</a> |
| 37 |
<ul> |
| 38 |
<li><a href="manual.html#introduction">Introduction</a></li> |
| 39 |
<li><a href="manual.html#installation">Installation</a></li> |
| 40 |
<li><a href="manual.html#reference">Reference</a></li> |
| 41 |
</ul> |
| 42 |
</li> |
| 43 |
<li><strong>Examples</strong></li> |
| 44 |
<li><a href="http://luaforge.net/projects/luazip/">Project</a> |
| 45 |
<ul> |
| 46 |
<li><a href="http://luaforge.net/tracker/?group_id=8">Bug Tracker</a></li> |
| 47 |
<li><a href="http://luaforge.net/scm/?group_id=8">CVS</a></li> |
| 48 |
</ul> |
| 49 |
</li> |
| 50 |
<li><a href="license.html">License</a></li> |
| 51 |
</ul> |
| 52 |
</div> |
| 53 |
|
| 54 |
<div id="content"> |
| 55 |
|
| 56 |
|
| 57 |
<h2><a name="examples"></a>Example</h2> |
| 58 |
|
| 59 |
<p> |
| 60 |
Suppose we have the following file hierarchy: |
| 61 |
</p> |
| 62 |
|
| 63 |
<pre class="example"> |
| 64 |
/a |
| 65 |
/b |
| 66 |
c.zip |
| 67 |
/a2 |
| 68 |
b2.ext2 |
| 69 |
/a3.ext3 |
| 70 |
/luazip.zip |
| 71 |
</pre> |
| 72 |
|
| 73 |
<ul> |
| 74 |
<li>c.zip contains the file 'd.txt'</li> |
| 75 |
<li>b2.ext2 is a zip file containing the file 'c2/d2.txt'</li> |
| 76 |
<li>a3.ext3 is a zip file containing the file 'b3/c3/d3.txt'</li> |
| 77 |
<li>luazip.zip contains the files 'luazip.h', 'luazip.c', 'Makefile', 'README'</li> |
| 78 |
</ul> |
| 79 |
|
| 80 |
Below is a small sample code displaying the basic use of the library. |
| 81 |
|
| 82 |
<pre class="example"> |
| 83 |
require "zip" |
| 84 |
|
| 85 |
local zfile, err = zip.open('luazip.zip') |
| 86 |
|
| 87 |
-- print the filenames of the files inside the zip |
| 88 |
for file in zfile:files() do |
| 89 |
print(file.filename) |
| 90 |
end |
| 91 |
|
| 92 |
-- open README and print it |
| 93 |
local f1, err = zfile:open('README') |
| 94 |
local s1 = f1:read("*a") |
| 95 |
print(s1) |
| 96 |
|
| 97 |
f1:close() |
| 98 |
zfile:close() |
| 99 |
|
| 100 |
-- open d.txt inside c.zip |
| 101 |
local d, err = zip.openfile('a/b/c/d.txt') |
| 102 |
assert(d, err) |
| 103 |
d:close() |
| 104 |
|
| 105 |
-- open d2.txt inside b2.ext2 |
| 106 |
local d2, err = zip.openfile('a2/b2/c2/d2.txt', "ext2") |
| 107 |
assert(d2, err) |
| 108 |
d2:close() |
| 109 |
|
| 110 |
-- open d3.txt inside a3.ext3 |
| 111 |
local d3, err = zip.openfile('a3/b3/c3/d3.txt', {"ext2", "ext3"}) |
| 112 |
assert(d3, err) |
| 113 |
d3:close() |
| 114 |
</pre> |
| 115 |
|
| 116 |
</div> |
| 117 |
|
| 118 |
</div> |
| 119 |
|
| 120 |
<div id="about"> |
| 121 |
<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p> |
| 122 |
<p><small> |
| 123 |
$Id: examples.html,v 1.4 2006/03/23 20:45:21 carregal Exp $ |
| 124 |
</small></p> |
| 125 |
</div> |
| 126 |
|
| 127 |
</div> |
| 128 |
|
| 129 |
</body> |
| 130 |
</html> |