summaryrefslogtreecommitdiff
path: root/Build/source/libs/luazip/doc/us/manual.html
blob: d9103af55392700d33af1fc63172fab052071ea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
    <title>LuaZip: Reading files inside zip files</title>
    <link rel="stylesheet" href="http://www.keplerproject.org/doc.css" type="text/css"/>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>

<div id="container">
	
<div id="product">
	<div id="product_logo">
        <a href="http://www.keplerproject.org"><img alt="LuaZip logo" src="luazip-128.png"/></a>
    </div>
	<div id="product_name"><big><strong>LuaZip</strong></big></div>
	<div id="product_description">Reading files inside zip files</div>
</div> <!-- id="product" -->

<div id="main">
	
<div id="navigation">
<h1>LuaZip</h1>
	<ul>
		<li><a href="index.html">Home</a>
			<ul>
				<li><a href="index.html#overview">Overview</a></li>
				<li><a href="index.html#status">Status</a></li>
				<li><a href="index.html#download">Download</a></li>
				<li><a href="index.html#history">History</a></li>
				<li><a href="index.html#credits">Credits</a></li>
				<li><a href="index.html#contact">Contact</a></li>
			</ul>
		</li>
		<li><strong>Manual</strong>
			<ul>
				<li><a href="manual.html#introduction">Introduction</a></li>
				<li><a href="manual.html#installation">Installation</a></li>
				<li><a href="manual.html#reference">Reference</a></li>
			</ul>
		</li>
		<li><a href="examples.html">Examples</a></li>
        <li><a href="http://luaforge.net/projects/luazip/">Project</a>
            <ul>
                <li><a href="http://luaforge.net/tracker/?group_id=8">Bug Tracker</a></li>
                <li><a href="http://luaforge.net/scm/?group_id=8">CVS</a></li>
            </ul>
        </li>
		<li><a href="license.html">License</a></li>
	</ul>
</div> <!-- id="navigation" -->

<div id="content">


<h2><a name="introduction"></a>Introduction</h2>

<p>LuaZip is a lightweight <a href="http://www.lua.org">Lua</a> 5.0 extension library
that can be used to read files stored inside zip files. It uses 
<a href="http://zziplib.sourceforge.net">zziplib</a> to do all the hard work.</p>

<p>The API exposed to Lua is very simple and very similiar to the usual file handling 
functions provided by the
<a href="http://www.lua.org/manual/5.0/manual.html#5.6">I/O Lua standard library</a>.
In fact, the API is so similar that parts of this manual are extracted from the Lua manual, 
copyrighted by Tecgraf, PUC-Rio.</p>

<h2><a name="installation"></a>Installation</h2>

<p>LuaZip follows the
<a href="http://www.keplerproject.org/compat/">package model</a>
for Lua 5.1, therefore it should be "installed". Refer to
<a href="http://www.keplerproject.org/compat/manual.html#configuration">
Compat-5.1 configuration</a> section about how to install the compiled
binary properly.</p>

<p>If you are using Unix you may need to download 
<a href="http://zziplib.sourceforge.net">zziplib 0.13.36</a></p>

<p>If you are using Windows, the binary version of LuaZip includes zziplib
(<code>zlib1.dll</code>). </p>

<h2><a name="reference"></a>Reference</h2>

<dl>
    <dt><strong>zip.open (filename)</strong></dt>
    <dd>This function opens a zip file and returns a new zip file handle. In case of 
    error it returns nil and an error message. Unlike <code>io.open</code>, there is no
    <code>mode</code> parameter, as the only supported mode is "read".</dd>

    <dt><strong>zip.openfile (filename [, extensions]])</strong></dt>
    <dd>This function opens a file and returns a file handle. In case of 
    error it returns nil and an error message. Unlike <code>io.open</code>, there is no
    <code>mode</code> parameter, as the only supported mode is "read".<br/>
    This function implements a virtual file system based on optionally compressed files.
    Instead of simply looking for a file at a given path, this function goes recursively up 
    through all path separators ("/") looking for zip files there. If it finds a zip file, 
    this function use the remaining path to open the requested file.<br/>
    The optional parameter <em>extensions</em> allows the use of file extensions other than .zip
    during the lookup. It can be a string corresponding to the extension or an indexed table
    with the lookup extensions sequence.</dd>

    <dt><strong>zfile:close ()</strong></dt>
    <dd>This function closes a zfile opened by <code>zip.open</code></dd>

    <dt><strong>zfile:files ()</strong></dt>
    <dd>Returns an iterator function that returns a new table containing the
    following information each time it is called:
    <ul>
        <li><code>filename</code>: the full path of a file</li>
        <li><code>compressed_size</code>: the compressed size of the file in bytes</li>
        <li><code>uncompressed_size</code>: the uncompressed size of the file in bytes</li>
    </ul>
    </dd>
    
    <dt><strong>zfile:open (filename)</strong></dt>
    <dd>This function opens a file that is stored inside the zip file opened by <code>zip.open</code>.<br/>
    The filename may contain the full path of the file contained inside the zip. The
    directory separator must be '/'.<br/>
    Unlike <code>f:open</code>, there is no <code>mode</code> parameter, as the only 
    supported mode is "read".</dd>
    
    <dt><strong>file:read (format1, ...)</strong></dt>
    <dd>Reads a <code>file</code> according to the given formats, which specify what to read.<br/>
    For each format, the function returns a string with the characters read, or nil if it cannot read
    data with the specified format. When called without formats, it uses a default format that reads
    the entire next line (see below).<br/>
    The available formats are:
    <ul>
    	<li><code>"*a"</code>: reads the whole file, starting at the current position. On end of file, it
    	returns the empty string.</li>
    	<li><code>"*l"</code>: reads the next line (skipping the end of line), returns nil on end of file.
    	This is the default format.</li>
    	<li><code><i>number</i></code>: reads a string with up to that number of characters, returning nil
    	on end of file.</li>
    </ul>
    <br/>
    Unlike the standard I/O read, the format <code>"*n"</code> is not supported.</dd>

    <dt><strong>file:seek ([whence] [, offset])</strong></dt>
    <dd>Sets and gets the file position, measured from the beginning of the file, to the position given
    by <code>offset</code> plus a base specified by the string <code>whence</code>, as follows:
    <ul>
	    <li><code>set</code>: base is position 0 (beginning of the file);</li>
	    <li><code>cur</code>: base is current position;</li>
	    <li><code>end</code>: base is end of file;</li>
    </ul>
    In case of success, function <code>seek</code> returns the final file position, measured in bytes 
    from the beginning of the file. If this function fails, it returns nil, plus an error string.
    The default value for <code>whence</code> is <code>"cur"</code>, and for <code>offset</code> is 0.
    Therefore, the call <code>file:seek()</code> returns the current file position, without changing
    it; the call <code>file:seek("set")</code> sets the position to the beginning of the file (and returns 0);
    and the call <code>file:seek("end")</code> sets the position to the end of the file, and returns its
    size.</dd>

    <dt><strong>file:close ()</strong></dt>
    <dd>This function closes a file opened by <code>zfile:open</code>.</dd>

    <dt><strong>file:lines ()</strong></dt>
    <dd>Returns an iterator function that returns a new line from the file each time it is called.
    Therefore, the construction<br/>
    <pre class="example">for line in file:lines() do ... end</pre>
    will iterate over all lines of the file.</dd>
</dl>

</div> <!-- id="content" -->

</div> <!-- id="main" -->

<div id="about">
	<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>
	<p><small>
	$Id: manual.html,v 1.10 2006/03/25 14:59:02 carregal Exp $
	</small></p>
</div> <!-- id="about" -->

</div> <!-- id="container" -->

</body>
</html>