cpl_minizip_unzip.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /* Modified version by Even Rouault. :
  2. - Addition of cpl_unzGetCurrentFileZStreamPos
  3. - Decoration of symbol names unz* -> cpl_unz*
  4. - Undef EXPORT so that we are sure the symbols are not exported
  5. - Add support for ZIP64
  6. * Copyright (c) 2008, Even Rouault <even dot rouault at mines-paris dot org>
  7. Original licence available in port/LICENCE_minizip
  8. */
  9. /* unzip.h -- IO for uncompress .zip files using zlib
  10. Version 1.01e, February 12th, 2005
  11. Copyright (C) 1998-2005 Gilles Vollant
  12. This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
  13. WinZip, InfoZip tools and compatible.
  14. Multi volume ZipFile (span) are not supported.
  15. Encryption compatible with pkzip 2.04g only supported
  16. Old compressions used by old PKZip 1.x are not supported
  17. I WAIT FEEDBACK at mail info@winimage.com
  18. Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
  19. Condition of use and distribution are the same than zlib :
  20. This software is provided 'as-is', without any express or implied
  21. warranty. In no event will the authors be held liable for any damages
  22. arising from the use of this software.
  23. Permission is granted to anyone to use this software for any purpose,
  24. including commercial applications, and to alter it and redistribute it
  25. freely, subject to the following restrictions:
  26. 1. The origin of this software must not be misrepresented; you must not
  27. claim that you wrote the original software. If you use this software
  28. in a product, an acknowledgment in the product documentation would be
  29. appreciated but is not required.
  30. 2. Altered source versions must be plainly marked as such, and must not be
  31. misrepresented as being the original software.
  32. 3. This notice may not be removed or altered from any source distribution.
  33. */
  34. /* for more info about .ZIP format, see
  35. http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
  36. http://www.info-zip.org/pub/infozip/doc/
  37. PkWare has also a specification at :
  38. ftp://ftp.pkware.com/probdesc.zip
  39. */
  40. #ifndef CPL_MINIZIP_UNZIP_H_INCLUDED
  41. #define CPL_MINIZIP_UNZIP_H_INCLUDED
  42. #include "cpl_vsi.h"
  43. #define uLong64 vsi_l_offset
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. #ifndef _ZLIB_H
  48. #include <zlib.h>
  49. #endif
  50. #ifndef CPL_MINIZIP_IOAPI_H_INCLUDED
  51. #include "cpl_minizip_ioapi.h"
  52. #endif
  53. /* GDAL addition */
  54. #define NOUNCRYPT
  55. #undef ZEXPORT
  56. #define ZEXPORT
  57. #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
  58. /* like the STRICT of WIN32, we define a pointer that cannot be converted
  59. from (void*) without cast */
  60. typedef struct TagunzFile__ { int unused; } unzFile__;
  61. typedef unzFile__ *unzFile;
  62. #else
  63. typedef voidp unzFile;
  64. #endif
  65. #define UNZ_OK (0)
  66. #define UNZ_END_OF_LIST_OF_FILE (-100)
  67. #define UNZ_ERRNO (Z_ERRNO)
  68. #define UNZ_EOF (0)
  69. #define UNZ_PARAMERROR (-102)
  70. #define UNZ_BADZIPFILE (-103)
  71. #define UNZ_INTERNALERROR (-104)
  72. #define UNZ_CRCERROR (-105)
  73. /* tm_unz contain date/time info */
  74. typedef struct tm_unz_s
  75. {
  76. uInt tm_sec; /* seconds after the minute - [0,59] */
  77. uInt tm_min; /* minutes after the hour - [0,59] */
  78. uInt tm_hour; /* hours since midnight - [0,23] */
  79. uInt tm_mday; /* day of the month - [1,31] */
  80. uInt tm_mon; /* months since January - [0,11] */
  81. uInt tm_year; /* years - [1980..2044] */
  82. } tm_unz;
  83. /* unz_global_info structure contain global data about the ZIPfile
  84. These data comes from the end of central dir */
  85. typedef struct unz_global_info_s
  86. {
  87. uLong64 number_entry; /* total number of entries in
  88. the central dir on this disk */
  89. uLong size_comment; /* size of the global comment of the zipfile */
  90. } unz_global_info;
  91. /* unz_file_info contain information about a file in the zipfile */
  92. typedef struct unz_file_info_s
  93. {
  94. uLong version; /* version made by 2 bytes */
  95. uLong version_needed; /* version needed to extract 2 bytes */
  96. uLong flag; /* general purpose bit flag 2 bytes */
  97. uLong compression_method; /* compression method 2 bytes */
  98. uLong dosDate; /* last mod file date in Dos fmt 4 bytes */
  99. uLong crc; /* crc-32 4 bytes */
  100. uLong64 compressed_size; /* compressed size 4 bytes */
  101. uLong64 uncompressed_size; /* uncompressed size 4 bytes */
  102. uLong size_filename; /* filename length 2 bytes */
  103. uLong size_file_extra; /* extra field length 2 bytes */
  104. uLong size_file_comment; /* file comment length 2 bytes */
  105. uLong disk_num_start; /* disk number start 2 bytes */
  106. uLong internal_fa; /* internal file attributes 2 bytes */
  107. uLong external_fa; /* external file attributes 4 bytes */
  108. tm_unz tmu_date;
  109. } unz_file_info;
  110. extern int ZEXPORT cpl_unzStringFileNameCompare OF ((const char* fileName1,
  111. const char* fileName2,
  112. int iCaseSensitivity));
  113. /*
  114. Compare two filename (fileName1,fileName2).
  115. If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
  116. If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
  117. or strcasecmp)
  118. If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
  119. (like 1 on Unix, 2 on Windows)
  120. */
  121. extern unzFile ZEXPORT cpl_unzOpen OF((const char *path));
  122. /*
  123. Open a Zip file. path contain the full pathname (by example,
  124. on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
  125. "zlib/zlib113.zip".
  126. If the zipfile cannot be opened (file don't exist or in not valid), the
  127. return value is NULL.
  128. Else, the return value is a unzFile Handle, usable with other function
  129. of this unzip package.
  130. */
  131. extern unzFile ZEXPORT cpl_unzOpen2 OF((const char *path,
  132. zlib_filefunc_def* pzlib_filefunc_def));
  133. /*
  134. Open a Zip file, like unzOpen, but provide a set of file low level API
  135. for read/write the zip file (see ioapi.h)
  136. */
  137. extern int ZEXPORT cpl_unzClose OF((unzFile file));
  138. /*
  139. Close a ZipFile opened with unzipOpen.
  140. If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
  141. these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
  142. return UNZ_OK if there is no problem. */
  143. extern int ZEXPORT cpl_unzGetGlobalInfo OF((unzFile file,
  144. unz_global_info *pglobal_info));
  145. /*
  146. Write info about the ZipFile in the *pglobal_info structure.
  147. No preparation of the structure is needed
  148. return UNZ_OK if there is no problem. */
  149. extern int ZEXPORT cpl_unzGetGlobalComment OF((unzFile file,
  150. char *szComment,
  151. uLong uSizeBuf));
  152. /*
  153. Get the global comment string of the ZipFile, in the szComment buffer.
  154. uSizeBuf is the size of the szComment buffer.
  155. return the number of byte copied or an error code <0
  156. */
  157. /***************************************************************************/
  158. /* Unzip package allow you browse the directory of the zipfile */
  159. extern int ZEXPORT cpl_unzGoToFirstFile OF((unzFile file));
  160. /*
  161. Set the current file of the zipfile to the first file.
  162. return UNZ_OK if there is no problem
  163. */
  164. extern int ZEXPORT cpl_unzGoToNextFile OF((unzFile file));
  165. /*
  166. Set the current file of the zipfile to the next file.
  167. return UNZ_OK if there is no problem
  168. return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
  169. */
  170. extern int ZEXPORT cpl_unzLocateFile OF((unzFile file,
  171. const char *szFileName,
  172. int iCaseSensitivity));
  173. /*
  174. Try locate the file szFileName in the zipfile.
  175. For the iCaseSensitivity signification, see unzStringFileNameCompare
  176. return value :
  177. UNZ_OK if the file is found. It becomes the current file.
  178. UNZ_END_OF_LIST_OF_FILE if the file is not found
  179. */
  180. /* ****************************************** */
  181. /* Ryan supplied functions */
  182. /* unz_file_info contain information about a file in the zipfile */
  183. typedef struct unz_file_pos_s
  184. {
  185. uLong64 pos_in_zip_directory; /* offset in zip file directory */
  186. uLong64 num_of_file; /* # of file */
  187. } unz_file_pos;
  188. extern int ZEXPORT cpl_unzGetFilePos(
  189. unzFile file,
  190. unz_file_pos* file_pos);
  191. extern int ZEXPORT cpl_unzGoToFilePos(
  192. unzFile file,
  193. unz_file_pos* file_pos);
  194. /* ****************************************** */
  195. extern int ZEXPORT cpl_unzGetCurrentFileInfo OF((unzFile file,
  196. unz_file_info *pfile_info,
  197. char *szFileName,
  198. uLong fileNameBufferSize,
  199. void *extraField,
  200. uLong extraFieldBufferSize,
  201. char *szComment,
  202. uLong commentBufferSize));
  203. /*
  204. Get Info about the current file
  205. if pfile_info!=NULL, the *pfile_info structure will contain somes info about
  206. the current file
  207. if szFileName!=NULL, the filemane string will be copied in szFileName
  208. (fileNameBufferSize is the size of the buffer)
  209. if extraField!=NULL, the extra field information will be copied in extraField
  210. (extraFieldBufferSize is the size of the buffer).
  211. This is the Central-header version of the extra field
  212. if szComment!=NULL, the comment string of the file will be copied in szComment
  213. (commentBufferSize is the size of the buffer)
  214. */
  215. /** Addition for GDAL : START */
  216. extern uLong64 ZEXPORT cpl_unzGetCurrentFileZStreamPos OF(( unzFile file));
  217. /** Addition for GDAL : END */
  218. /***************************************************************************/
  219. /* for reading the content of the current zipfile, you can open it, read data
  220. from it, and close it (you can close it before reading all the file)
  221. */
  222. extern int ZEXPORT cpl_unzOpenCurrentFile OF((unzFile file));
  223. /*
  224. Open for reading data the current file in the zipfile.
  225. If there is no error, the return value is UNZ_OK.
  226. */
  227. extern int ZEXPORT cpl_unzOpenCurrentFilePassword OF((unzFile file,
  228. const char* password));
  229. /*
  230. Open for reading data the current file in the zipfile.
  231. password is a crypting password
  232. If there is no error, the return value is UNZ_OK.
  233. */
  234. extern int ZEXPORT cpl_unzOpenCurrentFile2 OF((unzFile file,
  235. int* method,
  236. int* level,
  237. int raw));
  238. /*
  239. Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
  240. if raw==1
  241. *method will receive method of compression, *level will receive level of
  242. compression
  243. note : you can set level parameter as NULL (if you did not want known level,
  244. but you CANNOT set method parameter as NULL
  245. */
  246. extern int ZEXPORT cpl_unzOpenCurrentFile3 OF((unzFile file,
  247. int* method,
  248. int* level,
  249. int raw,
  250. const char* password));
  251. /*
  252. Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
  253. if raw==1
  254. *method will receive method of compression, *level will receive level of
  255. compression
  256. note : you can set level parameter as NULL (if you did not want known level,
  257. but you CANNOT set method parameter as NULL
  258. */
  259. extern int ZEXPORT cpl_unzCloseCurrentFile OF((unzFile file));
  260. /*
  261. Close the file in zip opened with unzOpenCurrentFile
  262. Return UNZ_CRCERROR if all the file was read but the CRC is not good
  263. */
  264. extern int ZEXPORT cpl_unzReadCurrentFile OF((unzFile file,
  265. voidp buf,
  266. unsigned len));
  267. /*
  268. Read bytes from the current file (opened by unzOpenCurrentFile)
  269. buf contain buffer where data must be copied
  270. len the size of buf.
  271. return the number of byte copied if somes bytes are copied
  272. return 0 if the end of file was reached
  273. return <0 with error code if there is an error
  274. (UNZ_ERRNO for IO error, or zLib error for uncompress error)
  275. */
  276. extern z_off_t ZEXPORT cpl_unztell OF((unzFile file));
  277. /*
  278. Give the current position in uncompressed data
  279. */
  280. extern int ZEXPORT cpl_unzeof OF((unzFile file));
  281. /*
  282. return 1 if the end of file was reached, 0 elsewhere
  283. */
  284. extern int ZEXPORT cpl_unzGetLocalExtrafield OF((unzFile file,
  285. voidp buf,
  286. unsigned len));
  287. /*
  288. Read extra field from the current file (opened by unzOpenCurrentFile)
  289. This is the local-header version of the extra field (sometimes, there is
  290. more info in the local-header version than in the central-header)
  291. if buf==NULL, it return the size of the local extra field
  292. if buf!=NULL, len is the size of the buffer, the extra header is copied in
  293. buf.
  294. the return value is the number of bytes copied in buf, or (if <0)
  295. the error code
  296. */
  297. /***************************************************************************/
  298. /* Get the current file offset */
  299. extern uLong64 ZEXPORT cpl_unzGetOffset (unzFile file);
  300. /* Set the current file offset */
  301. extern int ZEXPORT cpl_unzSetOffset (unzFile file, uLong64 pos);
  302. #ifdef __cplusplus
  303. }
  304. #endif
  305. #endif /* CPL_MINIZIP_UNZIP_H_INCLUDED */