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