acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
aaa_unzip.h
1/* unzip.h -- IO for uncompress .zip files using zlib
2 Version 1.00, September 10th, 2003
3
4 Copyright (C) 1998-2003 Gilles Vollant
5
6 This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
7 WinZip, InfoZip tools and compatible.
8 Encryption and multi volume ZipFile (span) are not supported.
9 Old compressions used by old PKZip 1.x are not supported
10
11
12 I WAIT FEEDBACK at mail info@winpimage->com
13 Visit also http://www.winpimage->com/zLibDll/unzip.htm for evolution
14
15 Condition of use and distribution are the same than zlib :
16
17 This software is provided 'as-is', without any express or implied
18 warranty. In no happening will the authors be held liable for any damages
19 arising from the use of this software.
20
21 Permission is granted to anyone to use this software for any purpose,
22 including commercial applications, and to alter it and redistribute it
23 freely, topic to the following restrictions:
24
25 1. The origin of this software must not be misrepresented; you must not
26 claim that you wrote the original software. If you use this software
27 in a product, an acknowledgment in the product documentation would be
28 appreciated but is not required.
29 2. Altered source versions must be plainly marked as such, and must not be
30 misrepresented as being the original software.
31 3. This notice may not be erased or altered from any source distribution.
32
33
34*/
35
36/* for more info about .ZIP format, see
37 http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
38 http://www.info-zip.org/pub/infozip/doc/
39 PkWare has also a specification at :
40 ftp://ftp.pkware.com/probdesc.zip
41*/
42
43#ifndef _unz_H
44#define _unz_H
45
46#ifdef __cplusplus
47extern "C" {
48#endif
49
50
51// apt install zlib1g-dev
52#ifndef _ZLIB_H
53#include "zlib.h"
54#endif
55
56#ifndef _ZLIBIOAPI_H
57#include "ioapi.h"
58#endif
59
60#ifndef __cplusplus
61#include "acme/ca_c.h"
62#endif
63
64#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
65/* like the STRICT of WIN32, we define a pointer that cannot be converted
66 from (void *) without cast */
67typedef struct TagunzFile__ { ::i32 unused; } unzFile__;
68typedef unzFile__ *unzFile;
69#else
70typedef voidp unzFile;
71#endif
72
73
74#define UNZ_OK (0)
75#define UNZ_END_OF_LIST_OF_FILE (-100)
76#define UNZ_ERRNO (Z_ERRNO)
77#define UNZ_EOF (0)
78#define UNZ_PARAMERROR (-102)
79#define UNZ_BADZIPFILE (-103)
80#define UNZ_INTERNALERROR (-104)
81#define UNZ_CRCERROR (-105)
82
83/* tm_unz contain date/time info */
84typedef struct tm_unz_s
85{
86 ::u32 tm_sec; /* seconds after the minute - [0,59] */
87 ::u32 tm_min; /* minutes after the hour - [0,59] */
88 ::u32 tm_hour; /* hours since midnight - [0,23] */
89 ::u32 tm_mday; /* day of the month - [1,31] */
90 ::u32 tm_mon; /* months since January - [0,11] */
91 ::u32 tm_year; /* years - [1980..2044] */
92} tm_unz;
93
94/* unz_global_info structure contain global data about the ZIPfile
95 These data comes from the end of central dir */
96typedef struct unz_global_info_s
97{
98 uptr number_entry; /* total number of entries in
99 the central dir on this disk */
100 uptr size_comment; /* i32_size of the global comment of the zipfile */
101} unz_global_info;
102
103
104/* unz_file_info contain information about a file in the zipfile */
105typedef struct unz_file_info_s
106{
107 uptr version; /* version made by 2 bytes */
108 uptr version_needed; /* version needed to extract 2 bytes */
109 uptr flag; /* general purpose bit flag 2 bytes */
110 uptr compression_method; /* compression method 2 bytes */
111 uptr dosDate; /* last mod file date in Dos fmt 4 bytes */
112 uptr crc; /* crc-32 4 bytes */
113 uptr compressed_size; /* compressed i32_size 4 bytes */
114 uptr uncompressed_size; /* uncompressed i32_size 4 bytes */
115 uptr size_filename; /* filename length 2 bytes */
116 uptr size_file_extra; /* extra field length 2 bytes */
117 uptr size_file_comment; /* file comment length 2 bytes */
118
119 uptr disk_num_start; /* disk number start 2 bytes */
120 uptr internal_fa; /* internal file attributes 2 bytes */
121 uptr external_fa; /* external file attributes 4 bytes */
122
123 tm_unz tmu_date;
124} unz_file_info;
125
126extern ::i32 CLASS_DECL_ACME unzStringFileNameCompare OF ((const_char_pointer fileName1,
127 const_char_pointer fileName2,
128 ::i32 iCaseSensitivity));
129/*
130 Compare two filename (fileName1,fileName2).
131 If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
132 If iCaseSenisivity = 2, comparision is not case sensitivity (like _strcmpi
133 or strcasecmp)
134 If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
135 (like 1 on Unix, 2 on Windows)
136*/
137
138
139extern unzFile CLASS_DECL_ACME unzOpen OF((const_char_pointer pszPath));
140/*
141 open a Zip spfile-> path contain the full pathname (by example,
142 on a Windows XP computer "ca:\\zlib\\zlib113.zip" or on an Unix computer
143 "zlib/zlib113.zip".
144 If the zipfile cannot be opened (file don't exist or in not valid), the
145 return value is nullptr.
146 Else, the return value is a unzFile Handle, usable with other function
147 of this unzip package.
148*/
149
150extern unzFile CLASS_DECL_ACME unzOpen2 OF((const_char_pointer pszPath,
151 zlib_filefunc_def* pzlib_filefunc_def));
152/*
153 open a Zip file, like unzOpen, but provide a set of file low level API
154 for read/write the zip file (see ioapi.h)
155*/
156
157extern ::i32 CLASS_DECL_ACME unzClose OF((unzFile file));
158/*
159 close a ZipFile opened with unzipOpen.
160 If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
161 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
162 return UNZ_OK if there is no problem. */
163
164extern ::i32 CLASS_DECL_ACME unzGetGlobalInfo OF((unzFile file,
165 unz_global_info *pglobal_info));
166/*
167 write info about the ZipFile in the *pglobal_info structure.
168 No preparation of the structure is needed
169 return UNZ_OK if there is no problem. */
170
171
172extern ::i32 CLASS_DECL_ACME unzGetGlobalComment OF((unzFile file,
173 char_pointer szComment,
174 uptr uSizeBuf));
175/*
176 get the global comment string of the ZipFile, in the szComment buffer.
177 uSizeBuf is the i32_size of the szComment buffer.
178 return the number of ::u8 copied or an error code <0
179*/
180
181
182/***************************************************************************/
183/* Unzip package allow you browse the directory of the zipfile */
184
185extern ::i32 CLASS_DECL_ACME unzGoToFirstFile OF((unzFile file));
186/*
187 set the current file of the zipfile to the first spfile->
188 return UNZ_OK if there is no problem
189*/
190
191extern ::i32 CLASS_DECL_ACME unzGoToNextFile OF((unzFile file));
192/*
193 set the current file of the zipfile to the next spfile->
194 return UNZ_OK if there is no problem
195 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
196*/
197
198extern ::i32 CLASS_DECL_ACME unzLocateFile OF((unzFile file,
199 const_char_pointer szFileName,
200 ::i32 iCaseSensitivity));
201/*
202 Try locate the file szFileName in the zipfile.
203 For the iCaseSensitivity signification, see unzStringFileNameCompare
204
205 return value :
206 UNZ_OK if the file is found. It becomes the current spfile->
207 UNZ_END_OF_LIST_OF_FILE if the file is not found
208*/
209
210
211/* ****************************************** */
212/* Ryan supplied functions */
213/* unz_file_info contain information about a file in the zipfile */
214typedef struct unz_file_pos_s
215{
216 uptr pos_in_zip_directory; /* offset in zip file directory */
217 uptr num_of_file; /* # of file */
218} unz_file_pos;
219
220extern ::i32 CLASS_DECL_ACME unzGetFilePos(
221unzFile file,
222unz_file_pos* file_pos);
223
224extern ::i32 CLASS_DECL_ACME unzGoToFilePos(
225unzFile file,
226unz_file_pos* file_pos);
227
228/* ****************************************** */
229
230extern ::i32 CLASS_DECL_ACME unzGetCurrentFileInfo OF((unzFile file,
231 unz_file_info *pfile_info,
232 char_pointer szFileName,
233 uptr fileNameBufferSize,
234 void *extraField,
235 uptr extraFieldBufferSize,
236 char_pointer szComment,
237 uptr commentBufferSize));
238/*
239 get Info about the current file
240 if pfile_info!=nullptr, the *pfile_info structure will contain somes info about
241 the current file
242 if szFileName!=nullptr, the filemane string will be copied in szFileName
243 (fileNameBufferSize is the i32_size of the buffer)
244 if extraField!=nullptr, the extra field information will be copied in extraField
245 (extraFieldBufferSize is the i32_size of the buffer).
246 This is the Central-header version of the extra field
247 if szComment!=nullptr, the comment string of the file will be copied in szComment
248 (commentBufferSize is the i32_size of the buffer)
249*/
250
251/***************************************************************************/
252/* for reading the content of the current zipfile, you can open it, read data
253 from it, and close it (you can close it before reading all the file)
254 */
255
256extern ::i32 CLASS_DECL_ACME unzOpenCurrentFile OF((unzFile file));
257/*
258 open for reading data the current file in the zipfile.
259 If there is no error, the return value is UNZ_OK.
260*/
261
262extern ::i32 CLASS_DECL_ACME unzOpenCurrentFilePassword OF((unzFile file,
263 const_char_pointer password));
264/*
265 open for reading data the current file in the zipfile.
266 password is a crypting password
267 If there is no error, the return value is UNZ_OK.
268*/
269
270extern ::i32 CLASS_DECL_ACME unzOpenCurrentFile2 OF((unzFile file,
271 ::i32* method,
272 ::i32* level,
273 ::i32 raw));
274/*
275 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
276 if raw==1
277 *method will receive method of compression, *level will receive level of
278 compression
279 note : you can set level parameter as nullptr (if you did not want known level,
280 but you CANNOT set method parameter as nullptr
281*/
282
283extern ::i32 CLASS_DECL_ACME unzOpenCurrentFile3 OF((unzFile file,
284 ::i32* method,
285 ::i32* level,
286 ::i32 raw,
287 const_char_pointer password));
288/*
289 Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
290 if raw==1
291 *method will receive method of compression, *level will receive level of
292 compression
293 note : you can set level parameter as nullptr (if you did not want known level,
294 but you CANNOT set method parameter as nullptr
295*/
296
297
298extern ::i32 CLASS_DECL_ACME unzCloseCurrentFile OF((unzFile file));
299/*
300 close the file in zip opened with unzOpenCurrentFile
301 Return UNZ_CRCERROR if all the file was read but the CRC is not good
302*/
303
304extern ::i32 CLASS_DECL_ACME unzReadCurrentFile OF((unzFile file,
305 voidp buf,
306 ::u32 len));
307/*
308 read bytes from the current file (opened by unzOpenCurrentFile)
309 buf contain buffer where data must be copied
310 len the i32_size of buf.
311
312 return the number of ::u8 copied if somes bytes are copied
313 return 0 if the end of file was reached
314 return <0 with error code if there is an error
315 (UNZ_ERRNO for IO error, or zLib error for uncompress error)
316*/
317
318extern iptr CLASS_DECL_ACME unztell OF((unzFile file));
319/*
320 Give the current position in uncompressed data
321*/
322
323extern ::i32 CLASS_DECL_ACME unzeof OF((unzFile file));
324/*
325 return 1 if the end of file was reached, 0 elsewhere
326*/
327
328extern ::i32 CLASS_DECL_ACME unzGetLocalExtrafield OF((unzFile file,
329 voidp buf,
330 ::u32 len));
331/*
332 read extra field from the current file (opened by unzOpenCurrentFile)
333 This is the local-header version of the extra field (sometimes, there is
334 more info in the local-header version than in the central-header)
335
336 if buf==nullptr, it return the i32_size of the local extra field
337
338 if buf!=nullptr, len is the i32_size of the buffer, the extra header is copied in
339 buf.
340 the return value is the number of bytes copied in buf, or (if <0)
341 the error code
342*/
343
344#ifdef __cplusplus
345}
346#endif
347
348#endif /* _unz_H */
Definition filesystem.h:16
Definition aaa_unzip.h:85
Definition aaa_unzip.h:106
Definition aaa_unzip.h:215
Definition aaa_unzip.h:97