ARX  1.0
The next-generation open source augmented reality toolkit.
Loading...
Searching...
No Matches
unzip.h
Go to the documentation of this file.
1/* unzip.h -- IO for uncompress .zip files using zlib
2 Version 1.2.0, September 16th, 2017
3 part of the MiniZip project
4
5 Copyright (C) 2012-2017 Nathan Moinvaziri
6 https://github.com/nmoinvaz/minizip
7 Copyright (C) 2009-2010 Mathias Svensson
8 Modifications for Zip64 support on both zip and unzip
9 http://result42.com
10 Copyright (C) 2007-2008 Even Rouault
11 Modifications of Unzip for Zip64
12 Copyright (C) 1998-2010 Gilles Vollant
13 http://www.winimage.com/zLibDll/minizip.html
14
15 This program is distributed under the terms of the same license as zlib.
16 See the accompanying LICENSE file for the full text of the license.
17*/
18
19#ifndef _UNZ_H
20#define _UNZ_H
21
22#ifdef __cplusplus
23extern "C" {
24#endif
25
26#ifndef _ZLIB_H
27#include "zlib.h"
28#endif
29
30#ifndef _ZLIBIOAPI_H
31#include "ioapi.h"
32#endif
33
34#ifdef HAVE_BZIP2
35#include "bzlib.h"
36#endif
37
38#define Z_BZIP2ED 12
39
40#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
41/* like the STRICT of WIN32, we define a pointer that cannot be converted
42 from (void*) without cast */
43typedef struct TagunzFile__ { int unused; } unz_file__;
44typedef unz_file__ *unzFile;
45#else
46typedef voidp unzFile;
47#endif
48
49#define UNZ_OK (0)
50#define UNZ_END_OF_LIST_OF_FILE (-100)
51#define UNZ_ERRNO (Z_ERRNO)
52#define UNZ_EOF (0)
53#define UNZ_PARAMERROR (-102)
54#define UNZ_BADZIPFILE (-103)
55#define UNZ_INTERNALERROR (-104)
56#define UNZ_CRCERROR (-105)
57#define UNZ_BADPASSWORD (-106)
58
59/* unz_global_info structure contain global data about the ZIPfile
60 These data comes from the end of central dir */
61typedef struct unz_global_info64_s
62{
63 uint64_t number_entry; /* total number of entries in the central dir on this disk */
64 uint32_t number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/
65 uint16_t size_comment; /* size of the global comment of the zipfile */
67
68typedef struct unz_global_info_s
69{
70 uint32_t number_entry; /* total number of entries in the central dir on this disk */
71 uint32_t number_disk_with_CD; /* number the the disk with central dir, used for spanning ZIP*/
72 uint16_t size_comment; /* size of the global comment of the zipfile */
74
75/* unz_file_info contain information about a file in the zipfile */
76typedef struct unz_file_info64_s
77{
78 uint16_t version; /* version made by 2 bytes */
79 uint16_t version_needed; /* version needed to extract 2 bytes */
80 uint16_t flag; /* general purpose bit flag 2 bytes */
81 uint16_t compression_method; /* compression method 2 bytes */
82 uint32_t dos_date; /* last mod file date in Dos fmt 4 bytes */
83 uint32_t crc; /* crc-32 4 bytes */
84 uint64_t compressed_size; /* compressed size 8 bytes */
85 uint64_t uncompressed_size; /* uncompressed size 8 bytes */
86 uint16_t size_filename; /* filename length 2 bytes */
87 uint16_t size_file_extra; /* extra field length 2 bytes */
88 uint16_t size_file_comment; /* file comment length 2 bytes */
89
90 uint32_t disk_num_start; /* disk number start 4 bytes */
91 uint16_t internal_fa; /* internal file attributes 2 bytes */
92 uint32_t external_fa; /* external file attributes 4 bytes */
93
94 uint64_t disk_offset;
95
98
99typedef struct unz_file_info_s
100{
101 uint16_t version; /* version made by 2 bytes */
102 uint16_t version_needed; /* version needed to extract 2 bytes */
103 uint16_t flag; /* general purpose bit flag 2 bytes */
104 uint16_t compression_method; /* compression method 2 bytes */
105 uint32_t dos_date; /* last mod file date in Dos fmt 4 bytes */
106 uint32_t crc; /* crc-32 4 bytes */
107 uint32_t compressed_size; /* compressed size 4 bytes */
108 uint32_t uncompressed_size; /* uncompressed size 4 bytes */
109 uint16_t size_filename; /* filename length 2 bytes */
110 uint16_t size_file_extra; /* extra field length 2 bytes */
111 uint16_t size_file_comment; /* file comment length 2 bytes */
112
113 uint16_t disk_num_start; /* disk number start 2 bytes */
114 uint16_t internal_fa; /* internal file attributes 2 bytes */
115 uint32_t external_fa; /* external file attributes 4 bytes */
116
117 uint64_t disk_offset;
119
120/***************************************************************************/
121/* Opening and close a zip file */
122
123extern unzFile ZEXPORT unzOpen(const char *path);
124extern unzFile ZEXPORT unzOpen64(const void *path);
125/* Open a Zip file.
126
127 path should contain the full path (by example, on a Windows XP computer
128 "c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip".
129 return NULL if zipfile cannot be opened or doesn't exist
130 return unzFile handle if no error
131
132 NOTE: The "64" function take a const void *pointer, because the path is just the value passed to the
133 open64_file_func callback. Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
134 is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char *does not describe the reality */
135
136extern unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def);
137/* Open a Zip file, like unzOpen, but provide a set of file low level API for read/write operations */
138extern unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def);
139/* Open a Zip file, like unz64Open, but provide a set of file low level API for read/write 64-bit operations */
140
141extern int ZEXPORT unzClose(unzFile file);
142/* Close a ZipFile opened with unzOpen. If there is files inside the .Zip opened with unzOpenCurrentFile,
143 these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
144
145 return UNZ_OK if there is no error */
146
147extern int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info);
148extern int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info);
149/* Write info about the ZipFile in the *pglobal_info structure.
150
151 return UNZ_OK if no error */
152
153extern int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size);
154/* Get the global comment string of the ZipFile, in the comment buffer.
155
156 uSizeBuf is the size of the szComment buffer.
157 return the number of byte copied or an error code <0 */
158
159/***************************************************************************/
160/* Reading the content of the current zipfile, you can open it, read data from it, and close it
161 (you can close it before reading all the file) */
162
163extern int ZEXPORT unzOpenCurrentFile(unzFile file);
164/* Open for reading data the current file in the zipfile.
165
166 return UNZ_OK if no error */
167
168extern int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password);
169/* Open for reading data the current file in the zipfile.
170 password is a crypting password
171
172 return UNZ_OK if no error */
173
174extern int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw);
175/* Same as unzOpenCurrentFile, but open for read raw the file (not uncompress)
176 if raw==1 *method will receive method of compression, *level will receive level of compression
177
178 NOTE: you can set level parameter as NULL (if you did not want known level,
179 but you CANNOT set method parameter as NULL */
180
181extern int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password);
182/* Same as unzOpenCurrentFile, but takes extra parameter password for encrypted files */
183
184extern int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, uint32_t len);
185/* Read bytes from the current file (opened by unzOpenCurrentFile)
186 buf contain buffer where data must be copied
187 len the size of buf.
188
189 return the number of byte copied if somes bytes are copied
190 return 0 if the end of file was reached
191 return <0 with error code if there is an error (UNZ_ERRNO for IO error, or zLib error for uncompress error) */
192
193extern int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename,
194 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
195extern int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *filename,
196 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
197/* Get Info about the current file
198
199 pfile_info if != NULL, the *pfile_info structure will contain somes info about the current file
200 filename if != NULL, the file name string will be copied in filename
201 filename_size is the size of the filename buffer
202 extrafield if != NULL, the extra field information from the central header will be copied in to
203 extrafield_size is the size of the extraField buffer
204 comment if != NULL, the comment string of the file will be copied in to
205 comment_size is the size of the comment buffer */
206
207extern int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, uint32_t len);
208/* Read extra field from the current file (opened by unzOpenCurrentFile)
209 This is the local-header version of the extra field (sometimes, there is
210 more info in the local-header version than in the central-header)
211
212 if buf == NULL, it return the size of the local extra field
213 if buf != NULL, len is the size of the buffer, the extra header is copied in buf.
214
215 return number of bytes copied in buf, or (if <0) the error code */
216
217extern int ZEXPORT unzCloseCurrentFile(unzFile file);
218/* Close the file in zip opened with unzOpenCurrentFile
219
220 return UNZ_CRCERROR if all the file was read but the CRC is not good */
221
222/***************************************************************************/
223/* Browse the directory of the zipfile */
224
225typedef int (*unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2);
226typedef int (*unzIteratorFunction)(unzFile file);
227typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename,
228 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
229
230extern int ZEXPORT unzGoToFirstFile(unzFile file);
231/* Set the current file of the zipfile to the first file.
232
233 return UNZ_OK if no error */
234
235extern int ZEXPORT unzGoToFirstFile2(unzFile file, unz_file_info64 *pfile_info, char *filename,
236 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
237/* Set the current file of the zipfile to the first file and retrieves the current info on success.
238 Not as seek intensive as unzGoToFirstFile + unzGetCurrentFileInfo.
239
240 return UNZ_OK if no error */
241
242extern int ZEXPORT unzGoToNextFile(unzFile file);
243/* Set the current file of the zipfile to the next file.
244
245 return UNZ_OK if no error
246 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
247
248extern int ZEXPORT unzGoToNextFile2(unzFile file, unz_file_info64 *pfile_info, char *filename,
249 uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size);
250/* Set the current file of the zipfile to the next file and retrieves the current
251 info on success. Does less seeking around than unzGotoNextFile + unzGetCurrentFileInfo.
252
253 return UNZ_OK if no error
254 return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest */
255
256extern int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func);
257/* Try locate the file szFileName in the zipfile. For custom filename comparison pass in comparison function.
258
259 return UNZ_OK if the file is found (it becomes the current file)
260 return UNZ_END_OF_LIST_OF_FILE if the file is not found */
261
262/***************************************************************************/
263/* Raw access to zip file */
264
265typedef struct unz_file_pos_s
266{
267 uint32_t pos_in_zip_directory; /* offset in zip file directory */
268 uint32_t num_of_file; /* # of file */
270
271extern int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos);
272extern int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos);
273
274typedef struct unz64_file_pos_s
275{
276 uint64_t pos_in_zip_directory; /* offset in zip file directory */
277 uint64_t num_of_file; /* # of file */
279
280extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos);
281extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos);
282
283extern int32_t ZEXPORT unzGetOffset(unzFile file);
284extern int64_t ZEXPORT unzGetOffset64(unzFile file);
285/* Get the current file offset */
286
287extern int ZEXPORT unzSetOffset(unzFile file, uint32_t pos);
288extern int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos);
289/* Set the current file offset */
290
291extern int32_t ZEXPORT unzTell(unzFile file);
292extern int64_t ZEXPORT unzTell64(unzFile file);
293/* return current position in uncompressed data */
294
295extern int ZEXPORT unzSeek(unzFile file, uint32_t offset, int origin);
296extern int ZEXPORT unzSeek64(unzFile file, uint64_t offset, int origin);
297/* Seek within the uncompressed data if compression method is storage */
298
299extern int ZEXPORT unzEndOfFile(unzFile file);
300/* return 1 if the end of file was reached, 0 elsewhere */
301
302/***************************************************************************/
303
304#ifdef __cplusplus
305}
306#endif
307
308#endif /* _UNZ_H */
Definition: unzip.h:275
uint64_t num_of_file
Definition: unzip.h:277
uint64_t pos_in_zip_directory
Definition: unzip.h:276
Definition: unzip.h:77
uint16_t flag
Definition: unzip.h:80
uint16_t size_filename
Definition: unzip.h:86
uint32_t crc
Definition: unzip.h:83
uint64_t uncompressed_size
Definition: unzip.h:85
uint16_t size_file_extra_internal
Definition: unzip.h:96
uint16_t internal_fa
Definition: unzip.h:91
uint16_t size_file_comment
Definition: unzip.h:88
uint16_t size_file_extra
Definition: unzip.h:87
uint64_t disk_offset
Definition: unzip.h:94
uint16_t version_needed
Definition: unzip.h:79
uint64_t compressed_size
Definition: unzip.h:84
uint32_t disk_num_start
Definition: unzip.h:90
uint32_t dos_date
Definition: unzip.h:82
uint16_t version
Definition: unzip.h:78
uint32_t external_fa
Definition: unzip.h:92
uint16_t compression_method
Definition: unzip.h:81
Definition: unzip.h:100
uint16_t size_filename
Definition: unzip.h:109
uint16_t version
Definition: unzip.h:101
uint64_t disk_offset
Definition: unzip.h:117
uint16_t flag
Definition: unzip.h:103
uint16_t disk_num_start
Definition: unzip.h:113
uint32_t external_fa
Definition: unzip.h:115
uint16_t version_needed
Definition: unzip.h:102
uint32_t compressed_size
Definition: unzip.h:107
uint16_t size_file_comment
Definition: unzip.h:111
uint32_t crc
Definition: unzip.h:106
uint32_t uncompressed_size
Definition: unzip.h:108
uint16_t size_file_extra
Definition: unzip.h:110
uint16_t compression_method
Definition: unzip.h:104
uint32_t dos_date
Definition: unzip.h:105
uint16_t internal_fa
Definition: unzip.h:114
Definition: unzip.h:266
uint32_t pos_in_zip_directory
Definition: unzip.h:267
uint32_t num_of_file
Definition: unzip.h:268
Definition: unzip.h:62
uint16_t size_comment
Definition: unzip.h:65
uint64_t number_entry
Definition: unzip.h:63
uint32_t number_disk_with_CD
Definition: unzip.h:64
Definition: unzip.h:69
uint32_t number_entry
Definition: unzip.h:70
uint16_t size_comment
Definition: unzip.h:72
uint32_t number_disk_with_CD
Definition: unzip.h:71
Definition: ioapi.h:109
Definition: ioapi.h:91
int ZEXPORT unzOpenCurrentFilePassword(unzFile file, const char *password)
Definition: unzip.c:1272
int(* unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, char *filename, uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size)
Definition: unzip.h:227
int ZEXPORT unzSeek(unzFile file, uint32_t offset, int origin)
Definition: unzip.c:1906
int ZEXPORT unzGetFilePos(unzFile file, unz_file_pos *file_pos)
Definition: unzip.c:1778
int64_t ZEXPORT unzTell64(unzFile file)
Definition: unzip.c:1895
int ZEXPORT unzSetOffset(unzFile file, uint32_t pos)
Definition: unzip.c:1862
int ZEXPORT unzLocateFile(unzFile file, const char *filename, unzFileNameComparer filename_compare_func)
Definition: unzip.c:1733
int32_t ZEXPORT unzTell(unzFile file)
Definition: unzip.c:1884
unzFile ZEXPORT unzOpen2_64(const void *path, zlib_filefunc64_def *pzlib_filefunc_def)
Definition: unzip.c:511
int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos *file_pos)
Definition: unzip.c:1800
int ZEXPORT unzGoToFirstFile2(unzFile file, unz_file_info64 *pfile_info, char *filename, uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size)
Definition: unzip.c:1665
unzFile ZEXPORT unzOpen(const char *path)
Definition: unzip.c:524
int ZEXPORT unzGoToFirstFile(unzFile file)
Definition: unzip.c:1691
int ZEXPORT unzGetGlobalComment(unzFile file, char *comment, uint16_t comment_size)
Definition: unzip.c:621
int ZEXPORT unzOpenCurrentFile2(unzFile file, int *method, int *level, int raw)
Definition: unzip.c:1277
int ZEXPORT unzGoToNextFile2(unzFile file, unz_file_info64 *pfile_info, char *filename, uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size)
Definition: unzip.c:1696
int32_t ZEXPORT unzGetOffset(unzFile file)
Definition: unzip.c:1835
int ZEXPORT unzOpenCurrentFile3(unzFile file, int *method, int *level, int raw, const char *password)
Definition: unzip.c:1034
int(* unzFileNameComparer)(unzFile file, const char *filename1, const char *filename2)
Definition: unzip.h:225
int ZEXPORT unzOpenCurrentFile(unzFile file)
Definition: unzip.c:1267
int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos *file_pos)
Definition: unzip.c:1815
int ZEXPORT unzGoToFilePos(unzFile file, unz_file_pos *file_pos)
Definition: unzip.c:1790
int ZEXPORT unzGetCurrentFileInfo64(unzFile file, unz_file_info64 *pfile_info, char *filename, uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size)
Definition: unzip.c:929
int ZEXPORT unzEndOfFile(unzFile file)
Definition: unzip.c:1974
int(* unzIteratorFunction)(unzFile file)
Definition: unzip.h:226
struct unz_global_info_s unz_global_info
int ZEXPORT unzGetGlobalInfo64(unzFile file, unz_global_info64 *pglobal_info)
Definition: unzip.c:611
int ZEXPORT unzGetCurrentFileInfo(unzFile file, unz_file_info *pfile_info, char *filename, uint16_t filename_size, void *extrafield, uint16_t extrafield_size, char *comment, uint16_t comment_size)
Definition: unzip.c:897
struct unz_global_info64_s unz_global_info64
unzFile ZEXPORT unzOpen64(const void *path)
Definition: unzip.c:529
struct unz_file_pos_s unz_file_pos
struct unz_file_info_s unz_file_info
int ZEXPORT unzGetLocalExtrafield(unzFile file, voidp buf, uint32_t len)
Definition: unzip.c:1564
struct unz_file_info64_s unz_file_info64
unzFile ZEXPORT unzOpen2(const char *path, zlib_filefunc_def *pzlib_filefunc_def)
Definition: unzip.c:500
int ZEXPORT unzCloseCurrentFile(unzFile file)
Definition: unzip.c:1600
int ZEXPORT unzReadCurrentFile(unzFile file, voidp buf, uint32_t len)
Definition: unzip.c:1289
int ZEXPORT unzGoToNextFile(unzFile file)
Definition: unzip.c:1728
struct unz64_file_pos_s unz64_file_pos
voidp unzFile
Definition: unzip.h:46
int64_t ZEXPORT unzGetOffset64(unzFile file)
Definition: unzip.c:1845
int ZEXPORT unzGetGlobalInfo(unzFile file, unz_global_info *pglobal_info)
Definition: unzip.c:598
int ZEXPORT unzClose(unzFile file)
Definition: unzip.c:534
int ZEXPORT unzSeek64(unzFile file, uint64_t offset, int origin)
Definition: unzip.c:1911
int ZEXPORT unzSetOffset64(unzFile file, uint64_t pos)
Definition: unzip.c:1867