| 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><strong>Manual</strong> |
| 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><a href="examples.html">Examples</a></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="introduction"></a>Introduction</h2> |
| 58 |
|
| 59 |
<p>LuaZip is a lightweight <a href="http://www.lua.org">Lua</a> 5.0 extension library |
| 60 |
that can be used to read files stored inside zip files. It uses |
| 61 |
<a href="http://zziplib.sourceforge.net">zziplib</a> to do all the hard work.</p> |
| 62 |
|
| 63 |
<p>The API exposed to Lua is very simple and very similiar to the usual file handling |
| 64 |
functions provided by the |
| 65 |
<a href="http://www.lua.org/manual/5.0/manual.html#5.6">I/O Lua standard library</a>. |
| 66 |
In fact, the API is so similar that parts of this manual are extracted from the Lua manual, |
| 67 |
copyrighted by Tecgraf, PUC-Rio.</p> |
| 68 |
|
| 69 |
<h2><a name="installation"></a>Installation</h2> |
| 70 |
|
| 71 |
<p>LuaZip follows the |
| 72 |
<a href="http://www.keplerproject.org/compat/">package model</a> |
| 73 |
for Lua 5.1, therefore it should be "installed". Refer to |
| 74 |
<a href="http://www.keplerproject.org/compat/manual.html#configuration"> |
| 75 |
Compat-5.1 configuration</a> section about how to install the compiled |
| 76 |
binary properly.</p> |
| 77 |
|
| 78 |
<p>If you are using Unix you may need to download |
| 79 |
<a href="http://zziplib.sourceforge.net">zziplib 0.13.36</a></p> |
| 80 |
|
| 81 |
<p>If you are using Windows, the binary version of LuaZip includes zziplib |
| 82 |
(<code>zlib1.dll</code>). </p> |
| 83 |
|
| 84 |
<h2><a name="reference"></a>Reference</h2> |
| 85 |
|
| 86 |
<dl> |
| 87 |
<dt><strong>zip.open (filename)</strong></dt> |
| 88 |
<dd>This function opens a zip file and returns a new zip file handle. In case of |
| 89 |
error it returns nil and an error message. Unlike <code>io.open</code>, there is no |
| 90 |
<code>mode</code> parameter, as the only supported mode is "read".</dd> |
| 91 |
|
| 92 |
<dt><strong>zip.openfile (filename [, extensions]])</strong></dt> |
| 93 |
<dd>This function opens a file and returns a file handle. In case of |
| 94 |
error it returns nil and an error message. Unlike <code>io.open</code>, there is no |
| 95 |
<code>mode</code> parameter, as the only supported mode is "read".<br/> |
| 96 |
This function implements a virtual file system based on optionally compressed files. |
| 97 |
Instead of simply looking for a file at a given path, this function goes recursively up |
| 98 |
through all path separators ("/") looking for zip files there. If it finds a zip file, |
| 99 |
this function use the remaining path to open the requested file.<br/> |
| 100 |
The optional parameter <em>extensions</em> allows the use of file extensions other than .zip |
| 101 |
during the lookup. It can be a string corresponding to the extension or an indexed table |
| 102 |
with the lookup extensions sequence.</dd> |
| 103 |
|
| 104 |
<dt><strong>zfile:close ()</strong></dt> |
| 105 |
<dd>This function closes a zfile opened by <code>zip.open</code></dd> |
| 106 |
|
| 107 |
<dt><strong>zfile:files ()</strong></dt> |
| 108 |
<dd>Returns an iterator function that returns a new table containing the |
| 109 |
following information each time it is called: |
| 110 |
<ul> |
| 111 |
<li><code>filename</code>: the full path of a file</li> |
| 112 |
<li><code>compressed_size</code>: the compressed size of the file in bytes</li> |
| 113 |
<li><code>uncompressed_size</code>: the uncompressed size of the file in bytes</li> |
| 114 |
</ul> |
| 115 |
</dd> |
| 116 |
|
| 117 |
<dt><strong>zfile:open (filename)</strong></dt> |
| 118 |
<dd>This function opens a file that is stored inside the zip file opened by <code>zip.open</code>.<br/> |
| 119 |
The filename may contain the full path of the file contained inside the zip. The |
| 120 |
directory separator must be '/'.<br/> |
| 121 |
Unlike <code>f:open</code>, there is no <code>mode</code> parameter, as the only |
| 122 |
supported mode is "read".</dd> |
| 123 |
|
| 124 |
<dt><strong>file:read (format1, ...)</strong></dt> |
| 125 |
<dd>Reads a <code>file</code> according to the given formats, which specify what to read.<br/> |
| 126 |
For each format, the function returns a string with the characters read, or nil if it cannot read |
| 127 |
data with the specified format. When called without formats, it uses a default format that reads |
| 128 |
the entire next line (see below).<br/> |
| 129 |
The available formats are: |
| 130 |
<ul> |
| 131 |
<li><code>"*a"</code>: reads the whole file, starting at the current position. On end of file, it |
| 132 |
returns the empty string.</li> |
| 133 |
<li><code>"*l"</code>: reads the next line (skipping the end of line), returns nil on end of file. |
| 134 |
This is the default format.</li> |
| 135 |
<li><code><i>number</i></code>: reads a string with up to that number of characters, returning nil |
| 136 |
on end of file.</li> |
| 137 |
</ul> |
| 138 |
<br/> |
| 139 |
Unlike the standard I/O read, the format <code>"*n"</code> is not supported.</dd> |
| 140 |
|
| 141 |
<dt><strong>file:seek ([whence] [, offset])</strong></dt> |
| 142 |
<dd>Sets and gets the file position, measured from the beginning of the file, to the position given |
| 143 |
by <code>offset</code> plus a base specified by the string <code>whence</code>, as follows: |
| 144 |
<ul> |
| 145 |
<li><code>set</code>: base is position 0 (beginning of the file);</li> |
| 146 |
<li><code>cur</code>: base is current position;</li> |
| 147 |
<li><code>end</code>: base is end of file;</li> |
| 148 |
</ul> |
| 149 |
In case of success, function <code>seek</code> returns the final file position, measured in bytes |
| 150 |
from the beginning of the file. If this function fails, it returns nil, plus an error string. |
| 151 |
The default value for <code>whence</code> is <code>"cur"</code>, and for <code>offset</code> is 0. |
| 152 |
Therefore, the call <code>file:seek()</code> returns the current file position, without changing |
| 153 |
it; the call <code>file:seek("set")</code> sets the position to the beginning of the file (and returns 0); |
| 154 |
and the call <code>file:seek("end")</code> sets the position to the end of the file, and returns its |
| 155 |
size.</dd> |
| 156 |
|
| 157 |
<dt><strong>file:close ()</strong></dt> |
| 158 |
<dd>This function closes a file opened by <code>zfile:open</code>.</dd> |
| 159 |
|
| 160 |
<dt><strong>file:lines ()</strong></dt> |
| 161 |
<dd>Returns an iterator function that returns a new line from the file each time it is called. |
| 162 |
Therefore, the construction<br/> |
| 163 |
<pre class="example">for line in file:lines() do ... end</pre> |
| 164 |
will iterate over all lines of the file.</dd> |
| 165 |
</dl> |
| 166 |
|
| 167 |
</div> |
| 168 |
|
| 169 |
</div> |
| 170 |
|
| 171 |
<div id="about"> |
| 172 |
<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> |
| 173 |
<p><small> |
| 174 |
$Id: manual.html,v 1.10 2006/03/25 14:59:02 carregal Exp $ |
| 175 |
</small></p> |
| 176 |
</div> |
| 177 |
|
| 178 |
</div> |
| 179 |
|
| 180 |
</body> |
| 181 |
</html> |