Unzip.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /* unzip.h -- IO for uncompress .zip files using zlib
  2. Version 0.15 beta, Mar 19th, 1998,
  3. Copyright (C) 1998 Gilles Vollant
  4. This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
  5. WinZip, InfoZip tools and compatible.
  6. Encryption and multi volume ZipFile (span) are not supported.
  7. Old compressions used by old PKZip 1.x are not supported
  8. THIS IS AN ALPHA VERSION. AT THIS STAGE OF DEVELOPPEMENT, SOMES API OR STRUCTURE
  9. CAN CHANGE IN FUTURE VERSION !!
  10. I WAIT FEEDBACK at mail info@winimage.com
  11. Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
  12. Condition of use and distribution are the same than zlib :
  13. This software is provided 'as-is', without any express or implied
  14. warranty. In no event will the authors be held liable for any damages
  15. arising from the use of this software.
  16. Permission is granted to anyone to use this software for any purpose,
  17. including commercial applications, and to alter it and redistribute it
  18. freely, subject to the following restrictions:
  19. 1. The origin of this software must not be misrepresented; you must not
  20. claim that you wrote the original software. If you use this software
  21. in a product, an acknowledgment in the product documentation would be
  22. appreciated but is not required.
  23. 2. Altered source versions must be plainly marked as such, and must not be
  24. misrepresented as being the original software.
  25. 3. This notice may not be removed or altered from any source distribution.
  26. */
  27. #ifndef __UNZIP_H__
  28. #define __UNZIP_H__
  29. #include "zlib/zlib.h"
  30. #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
  31. /* like the STRICT of WIN32, we define a pointer that cannot be converted
  32. from (void*) without cast */
  33. typedef struct TagunzFile__ { int unused; } unzFile__;
  34. typedef unzFile__ *unzFile;
  35. #else
  36. typedef void* unzFile;
  37. #endif
  38. /* tm_unz contain date/time info */
  39. typedef struct tm_unz_s
  40. {
  41. unsigned int tm_sec; /* seconds after the minute - [0,59] */
  42. unsigned int tm_min; /* minutes after the hour - [0,59] */
  43. unsigned int tm_hour; /* hours since midnight - [0,23] */
  44. unsigned int tm_mday; /* day of the month - [1,31] */
  45. unsigned int tm_mon; /* months since January - [0,11] */
  46. unsigned int tm_year; /* years - [1980..2044] */
  47. } tm_unz;
  48. /* unz_global_info structure contain global data about the ZIPfile
  49. These data comes from the end of central dir */
  50. typedef struct unz_global_info_s
  51. {
  52. unsigned long number_entry; /* total number of entries in the central dir on this disk */
  53. unsigned long size_comment; /* size of the global comment of the zipfile */
  54. } unz_global_info;
  55. /* unz_file_info contain information about a file in the zipfile */
  56. typedef struct unz_file_info_s
  57. {
  58. unsigned long version; /* version made by 2 unsigned chars */
  59. unsigned long version_needed; /* version needed to extract 2 unsigned chars */
  60. unsigned long flag; /* general purpose bit flag 2 unsigned chars */
  61. unsigned long compression_method; /* compression method 2 unsigned chars */
  62. unsigned long dosDate; /* last mod file date in Dos fmt 4 unsigned chars */
  63. unsigned long crc; /* crc-32 4 unsigned chars */
  64. unsigned long compressed_size; /* compressed size 4 unsigned chars */
  65. unsigned long uncompressed_size; /* uncompressed size 4 unsigned chars */
  66. unsigned long size_filename; /* filename length 2 unsigned chars */
  67. unsigned long size_file_extra; /* extra field length 2 unsigned chars */
  68. unsigned long size_file_comment; /* file comment length 2 unsigned chars */
  69. unsigned long disk_num_start; /* disk number start 2 unsigned chars */
  70. unsigned long internal_fa; /* internal file attributes 2 unsigned chars */
  71. unsigned long external_fa; /* external file attributes 4 unsigned chars */
  72. tm_unz tmu_date;
  73. } unz_file_info;
  74. /* unz_file_info_interntal contain internal info about a file in zipfile*/
  75. typedef struct unz_file_info_internal_s
  76. {
  77. unsigned long offset_curfile;/* relative offset of static header 4 unsigned chars */
  78. } unz_file_info_internal;
  79. /* file_in_zip_read_info_s contain internal information about a file in zipfile,
  80. when reading and decompress it */
  81. typedef struct
  82. {
  83. char *read_buffer; /* internal buffer for compressed data */
  84. z_stream stream; /* zLib stream structure for inflate */
  85. unsigned long pos_in_zipfile; /* position in unsigned char on the zipfile, for fseek*/
  86. unsigned long stream_initialised; /* flag set if stream structure is initialised*/
  87. unsigned long offset_local_extrafield;/* offset of the static extra field */
  88. unsigned int size_local_extrafield;/* size of the static extra field */
  89. unsigned long pos_local_extrafield; /* position in the static extra field in read*/
  90. unsigned long crc32; /* crc32 of all data uncompressed */
  91. unsigned long crc32_wait; /* crc32 we must obtain after decompress all */
  92. unsigned long rest_read_compressed; /* number of unsigned char to be decompressed */
  93. unsigned long rest_read_uncompressed;/*number of unsigned char to be obtained after decomp*/
  94. idFile * file; /* io structore of the zipfile */
  95. unsigned long compression_method; /* compression method (0==store) */
  96. unsigned long byte_before_the_zipfile;/* unsigned char before the zipfile, (>0 for sfx)*/
  97. } file_in_zip_read_info_s;
  98. /* unz_s contain internal information about the zipfile
  99. */
  100. typedef struct
  101. {
  102. idFile_Cached * file; /* io structore of the zipfile */
  103. unz_global_info gi; /* public global information */
  104. unsigned long byte_before_the_zipfile;/* unsigned char before the zipfile, (>0 for sfx)*/
  105. unsigned long num_file; /* number of the current file in the zipfile*/
  106. unsigned long pos_in_central_dir; /* pos of the current file in the central dir*/
  107. unsigned long current_file_ok; /* flag about the usability of the current file*/
  108. unsigned long central_pos; /* position of the beginning of the central dir*/
  109. unsigned long size_central_dir; /* size of the central directory */
  110. unsigned long offset_central_dir; /* offset of start of central directory with
  111. respect to the starting disk number */
  112. unz_file_info cur_file_info; /* public info about the current file in zip*/
  113. unz_file_info_internal cur_file_info_internal; /* private info about it*/
  114. file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
  115. file if we are decompressing it */
  116. } unz_s;
  117. #define UNZ_OK (0)
  118. #define UNZ_END_OF_LIST_OF_FILE (-100)
  119. #define UNZ_ERRNO (Z_ERRNO)
  120. #define UNZ_EOF (0)
  121. #define UNZ_PARAMERROR (-102)
  122. #define UNZ_BADZIPFILE (-103)
  123. #define UNZ_INTERNALERROR (-104)
  124. #define UNZ_CRCERROR (-105)
  125. #define UNZ_CASESENSITIVE 1
  126. #define UNZ_NOTCASESENSITIVE 2
  127. #define UNZ_OSDEFAULTCASE 0
  128. extern int unzStringFileNameCompare (const char* fileName1, const char* fileName2, int 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. extern unzFile unzOpen (const char *path);
  138. extern unzFile unzReOpen (const char* path, unzFile file);
  139. /*
  140. Open a Zip file. path contain the full pathname (by example,
  141. on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
  142. "zlib/zlib111.zip".
  143. If the zipfile cannot be opened (file don't exist or in not valid), the
  144. return value is NULL.
  145. Else, the return value is a unzFile Handle, usable with other function
  146. of this unzip package.
  147. */
  148. extern int unzClose (unzFile file);
  149. /*
  150. Close a ZipFile opened with unzipOpen.
  151. If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
  152. these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
  153. return UNZ_OK if there is no problem. */
  154. extern int unzGetGlobalInfo (unzFile file, unz_global_info *pglobal_info);
  155. /*
  156. Write info about the ZipFile in the *pglobal_info structure.
  157. No preparation of the structure is needed
  158. return UNZ_OK if there is no problem. */
  159. extern int unzGetGlobalComment (unzFile file, char *szComment, unsigned long uSizeBuf);
  160. /*
  161. Get the global comment string of the ZipFile, in the szComment buffer.
  162. uSizeBuf is the size of the szComment buffer.
  163. return the number of unsigned char copied or an error code <0
  164. */
  165. /***************************************************************************/
  166. /* Unzip package allow you browse the directory of the zipfile */
  167. extern int unzGoToFirstFile (unzFile file);
  168. /*
  169. Set the current file of the zipfile to the first file.
  170. return UNZ_OK if there is no problem
  171. */
  172. extern int unzGoToNextFile (unzFile file);
  173. /*
  174. Set the current file of the zipfile to the next file.
  175. return UNZ_OK if there is no problem
  176. return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
  177. */
  178. extern int unzGetCurrentFileInfoPosition (unzFile file, unsigned long *pos );
  179. /*
  180. Get the position of the info of the current file in the zip.
  181. return UNZ_OK if there is no problem
  182. */
  183. extern int unzSetCurrentFileInfoPosition (unzFile file, unsigned long pos );
  184. /*
  185. Set the position of the info of the current file in the zip.
  186. return UNZ_OK if there is no problem
  187. */
  188. extern int unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity);
  189. /*
  190. Try locate the file szFileName in the zipfile.
  191. For the iCaseSensitivity signification, see unzStringFileNameCompare
  192. return value :
  193. UNZ_OK if the file is found. It becomes the current file.
  194. UNZ_END_OF_LIST_OF_FILE if the file is not found
  195. */
  196. extern int unzGetCurrentFileInfo (unzFile file, unz_file_info *pfile_info, char *szFileName, unsigned long fileNameBufferSize, void *extraField, unsigned long extraFieldBufferSize, char *szComment, unsigned long commentBufferSize);
  197. /*
  198. Get Info about the current file
  199. if pfile_info!=NULL, the *pfile_info structure will contain somes info about
  200. the current file
  201. if szFileName!=NULL, the filemane string will be copied in szFileName
  202. (fileNameBufferSize is the size of the buffer)
  203. if extraField!=NULL, the extra field information will be copied in extraField
  204. (extraFieldBufferSize is the size of the buffer).
  205. This is the Central-header version of the extra field
  206. if szComment!=NULL, the comment string of the file will be copied in szComment
  207. (commentBufferSize is the size of the buffer)
  208. */
  209. /***************************************************************************/
  210. /* for reading the content of the current zipfile, you can open it, read data
  211. from it, and close it (you can close it before reading all the file)
  212. */
  213. extern int unzOpenCurrentFile (unzFile file);
  214. /*
  215. Open for reading data the current file in the zipfile.
  216. If there is no error, the return value is UNZ_OK.
  217. */
  218. extern int unzCloseCurrentFile (unzFile file);
  219. /*
  220. Close the file in zip opened with unzOpenCurrentFile
  221. Return UNZ_CRCERROR if all the file was read but the CRC is not good
  222. */
  223. extern int unzReadCurrentFile (unzFile file, void* buf, unsigned len);
  224. /*
  225. Read unsigned chars from the current file (opened by unzOpenCurrentFile)
  226. buf contain buffer where data must be copied
  227. len the size of buf.
  228. return the number of unsigned char copied if somes unsigned chars are copied
  229. return 0 if the end of file was reached
  230. return <0 with error code if there is an error
  231. (UNZ_ERRNO for IO error, or zLib error for uncompress error)
  232. */
  233. extern long unztell(unzFile file);
  234. /*
  235. Give the current position in uncompressed data
  236. */
  237. extern int unzeof (unzFile file);
  238. /*
  239. return 1 if the end of file was reached, 0 elsewhere
  240. */
  241. extern int unzGetLocalExtrafield (unzFile file, void* buf, unsigned len);
  242. /*
  243. Read extra field from the current file (opened by unzOpenCurrentFile)
  244. This is the local-header version of the extra field (sometimes, there is
  245. more info in the local-header version than in the central-header)
  246. if buf==NULL, it return the size of the local extra field
  247. if buf!=NULL, len is the size of the buffer, the extra header is copied in
  248. buf.
  249. the return value is the number of unsigned chars copied in buf, or (if <0)
  250. the error code
  251. */
  252. #endif /* __UNZIP_H__ */