1 <section><date> 1. June
2000 </date>
2 <h2> ZIP Access
</h2> Accessing Zip Archives with ZLib Decompression
10 The
<a href=
"zziplib.html">zziplib library
</a> offers users the
11 ability to easily extract data from files archived in a single
12 zip file. This way, programs that use many
"read-only" files from
13 a program specific source directory can have a single zip
17 This library offers only a (free) subset of compression methods
18 provided in a full implementation but that is well enough. The
19 idea here is that
<tt>zip/unzip
</tt> utilities can be used
20 to create archives that will later be read by using this library.
21 Yet those programmes (or a library with their functionality)
22 is not needed in that final operation.
26 <h3> Using A Zip-File
</h3>
29 Before a file in the zip-archive is accessed, the application
30 must first get a handle to the central directory contained in the
31 zip-file. This is achived by calling
32 <a href=
"zziplib.html#zzip_dir_open"> zzip_dir_open
</a>
34 <a href=
"zziplib.html#zzip_dir_fdopen"> zzip_dir_fdopen
</a>.
35 The directory entries in the zip-archives can be obtained
37 <a href=
"zziplib.html#zzip_dir_read"> zzip_dir_read
</a>.
38 After being done, the zip-dir handle should be closed with
39 <a href=
"zziplib.html#zzip_dir_close"> zzip_dir_close
</a>.
41 <p><pre> ZZIP_DIR* dir = zzip_dir_open(
"test.zip",
0);
44 if (zzip_dir_read(dir,
&dirent) {
45 /* show info for first file */
46 print(
"%s %i/%i", dirent.d_name, dirent.d_csize, dirent.st_size);
52 From the zip-dir handle a compressed file can be opened
53 for reading. This is achieved by using
54 <a href=
"zziplib.html#zzip_file_open"> zzip_file_open
</a>
55 and providing it with the dir-handle and a name of the file.
57 <a href=
"zziplib.html#zzip_file_read"> zzip_file_read
</a>
58 is used to get pieces of uncompressed data from the file, and
59 the file-handle should be closed with
60 <a href=
"zziplib.html#zzip_file_close"> zzip_file_close
</a>
62 <p><pre> ZZIP_FILE* fp = zzip_file_open(dir,
"README",
0);
65 zzip_ssize_t len = zzip_file_read(fp, buf,
10);
67 /* show head of README */
75 <h3> Magic Zipped Files
</h3>
78 There is actually no need to directly use the zip-centric functions
79 as described above. Instead there are magic replacements for the
80 posix calls
<code>open/read/close
</code> and
81 <code>opendir/readdir/closedir
</code>. The prototypes of these
82 functions had been the guideline for the design of their magic
84 <a href=
"zziplib.html">zziplib library
</a>.
87 The magic functions are described in a seperated document on
88 <a href=
"zzip-file.html"> Using Zipped Files
</a>. In general,
89 the functions have a prefix
<tt>zzip_
</tt> and their argument
90 types have a prefix
<tt>ZZIP_
</tt> where appropriate. Calls
91 to the magic functions and the direct functions above can
92 be mixed as long as the magic functions have not been opening
96 To detect a real file (or directory), the info functions
97 <a href=
"zziplib.html#zzip_file_real"> zzip_file_real
</a>
99 <a href=
"zziplib.html#zzip_dir_real"> zzip_dir_real
</a>
101 If these return a true value, the standard posix functions
102 are more apropriate. The posix handles can be obtained with
104 <a href=
"zziplib.html#zzip_realdir"> zzip_realdir
</a> and
105 <a href=
"zziplib.html#zzip_realfd"> zzip_realfd
</a> respectivly.
109 <h3> Errors
& Infos
</h3>
112 There are a set of error and info functions available. To handle
113 error conditions specific to the
114 <a href=
"zziplib.html">zziplib library
</a>
115 there are these functions:
116 <a href=
"zziplib.html#zzip_error"> zzip_error
</a>,
117 <a href=
"zziplib.html#zzip_seterror"> zzip_seterror
</a>
118 and their string representations with
119 <a href=
"zziplib.html#zzip_strerror"> zzip_strerror
</a>,
120 <a href=
"zziplib.html#zzip_strerror_of"> zzip_strerror_of
</a>.
121 The magic functions will map any of these specific library
122 error conditions to the more generic system
<code>errno
</code>
124 <a href=
"zziplib.html#zzip_errno"> zzip_errno
</a>.
127 More information on stream can be obtained with
128 <a href=
"zziplib.html#zzip_dir_stat"> zzip_dir_stat
</a> and
129 <a href=
"zziplib.html#zzip_dirhandle"> zzip_dirhandle.
</a>
130 The latter is used to obtain the dir-handle that every zipped file
131 handle has even if not explicitly opened.
134 The usage of many functions are shown in the example programs
135 that come along with the
136 <a href=
"zziplib.html">zziplib library
</a>. See the files
137 <a href=
"zzcat.c"> zzcat.c
</a> and
138 <a href=
"zzdir.c"> zzdir.c
</a>. The
139 <a href=
"zziptest.c"> zziptest.c
</a> program needs the
141 <a href=
"zzip.h"> zzip.h
</a> whereas the library installer
142 will only copy the public include file
143 <a href=
"zziplib.h"> zziplib.h
</a> to your system's
144 <tt>include
</tt> directory.