unzip.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
  2. /* like the STRICT of WIN32, we define a pointer that cannot be converted
  3. from (void*) without cast */
  4. typedef struct TagunzFile__ { int unused; } unzFile__;
  5. typedef unzFile__ *unzFile;
  6. #else
  7. typedef void* unzFile;
  8. #endif
  9. /* tm_unz contain date/time info */
  10. typedef struct tm_unz_s
  11. {
  12. unsigned int tm_sec; /* seconds after the minute - [0,59] */
  13. unsigned int tm_min; /* minutes after the hour - [0,59] */
  14. unsigned int tm_hour; /* hours since midnight - [0,23] */
  15. unsigned int tm_mday; /* day of the month - [1,31] */
  16. unsigned int tm_mon; /* months since January - [0,11] */
  17. unsigned int tm_year; /* years - [1980..2044] */
  18. } tm_unz;
  19. /* unz_global_info structure contain global data about the ZIPfile
  20. These data comes from the end of central dir */
  21. typedef struct unz_global_info_s
  22. {
  23. unsigned long number_entry; /* total number of entries in the central dir on this disk */
  24. unsigned long size_comment; /* size of the global comment of the zipfile */
  25. } unz_global_info;
  26. /* unz_file_info contain information about a file in the zipfile */
  27. typedef struct unz_file_info_s
  28. {
  29. unsigned long version; /* version made by 2 unsigned chars */
  30. unsigned long version_needed; /* version needed to extract 2 unsigned chars */
  31. unsigned long flag; /* general purpose bit flag 2 unsigned chars */
  32. unsigned long compression_method; /* compression method 2 unsigned chars */
  33. unsigned long dosDate; /* last mod file date in Dos fmt 4 unsigned chars */
  34. unsigned long crc; /* crc-32 4 unsigned chars */
  35. unsigned long compressed_size; /* compressed size 4 unsigned chars */
  36. unsigned long uncompressed_size; /* uncompressed size 4 unsigned chars */
  37. unsigned long size_filename; /* filename length 2 unsigned chars */
  38. unsigned long size_file_extra; /* extra field length 2 unsigned chars */
  39. unsigned long size_file_comment; /* file comment length 2 unsigned chars */
  40. unsigned long disk_num_start; /* disk number start 2 unsigned chars */
  41. unsigned long internal_fa; /* internal file attributes 2 unsigned chars */
  42. unsigned long external_fa; /* external file attributes 4 unsigned chars */
  43. tm_unz tmu_date;
  44. } unz_file_info;
  45. /* unz_file_info_interntal contain internal info about a file in zipfile*/
  46. typedef struct unz_file_info_internal_s
  47. {
  48. unsigned long offset_curfile;/* relative offset of static header 4 unsigned chars */
  49. } unz_file_info_internal;
  50. typedef void* (*alloc_func) (void* opaque, unsigned int items, unsigned int size);
  51. typedef void (*free_func) (void* opaque, void* address);
  52. struct internal_state;
  53. typedef struct z_stream_s {
  54. unsigned char *next_in; /* next input unsigned char */
  55. unsigned int avail_in; /* number of unsigned chars available at next_in */
  56. unsigned long total_in; /* total nb of input unsigned chars read so */
  57. unsigned char *next_out; /* next output unsigned char should be put there */
  58. unsigned int avail_out; /* remaining free space at next_out */
  59. unsigned long total_out; /* total nb of unsigned chars output so */
  60. char *msg; /* last error message, NULL if no error */
  61. struct internal_state *state; /* not visible by applications */
  62. alloc_func zalloc; /* used to allocate the internal state */
  63. free_func zfree; /* used to free the internal state */
  64. unsigned char* opaque; /* private data object passed to zalloc and zfree */
  65. int data_type; /* best guess about the data type: ascii or binary */
  66. unsigned long adler; /* adler32 value of the uncompressed data */
  67. unsigned long reserved; /* reserved for future use */
  68. } z_stream;
  69. typedef z_stream *z_streamp;
  70. /* file_in_zip_read_info_s contain internal information about a file in zipfile,
  71. when reading and decompress it */
  72. typedef struct
  73. {
  74. char *read_buffer; /* internal buffer for compressed data */
  75. z_stream stream; /* zLib stream structure for inflate */
  76. unsigned long pos_in_zipfile; /* position in unsigned char on the zipfile, for fseek*/
  77. unsigned long stream_initialised; /* flag set if stream structure is initialised*/
  78. unsigned long offset_local_extrafield;/* offset of the static extra field */
  79. unsigned int size_local_extrafield;/* size of the static extra field */
  80. unsigned long pos_local_extrafield; /* position in the static extra field in read*/
  81. unsigned long crc32; /* crc32 of all data uncompressed */
  82. unsigned long crc32_wait; /* crc32 we must obtain after decompress all */
  83. unsigned long rest_read_compressed; /* number of unsigned char to be decompressed */
  84. unsigned long rest_read_uncompressed;/*number of unsigned char to be obtained after decomp*/
  85. FILE* file; /* io structore of the zipfile */
  86. unsigned long compression_method; /* compression method (0==store) */
  87. unsigned long byte_before_the_zipfile;/* unsigned char before the zipfile, (>0 for sfx)*/
  88. } file_in_zip_read_info_s;
  89. /* unz_s contain internal information about the zipfile
  90. */
  91. typedef struct
  92. {
  93. FILE* file; /* io structore of the zipfile */
  94. unz_global_info gi; /* public global information */
  95. unsigned long byte_before_the_zipfile;/* unsigned char before the zipfile, (>0 for sfx)*/
  96. unsigned long num_file; /* number of the current file in the zipfile*/
  97. unsigned long pos_in_central_dir; /* pos of the current file in the central dir*/
  98. unsigned long current_file_ok; /* flag about the usability of the current file*/
  99. unsigned long central_pos; /* position of the beginning of the central dir*/
  100. unsigned long size_central_dir; /* size of the central directory */
  101. unsigned long offset_central_dir; /* offset of start of central directory with
  102. respect to the starting disk number */
  103. unz_file_info cur_file_info; /* public info about the current file in zip*/
  104. unz_file_info_internal cur_file_info_internal; /* private info about it*/
  105. file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
  106. file if we are decompressing it */
  107. } unz_s;
  108. #define UNZ_OK (0)
  109. #define UNZ_END_OF_LIST_OF_FILE (-100)
  110. #define UNZ_ERRNO (Z_ERRNO)
  111. #define UNZ_EOF (0)
  112. #define UNZ_PARAMERROR (-102)
  113. #define UNZ_BADZIPFILE (-103)
  114. #define UNZ_INTERNALERROR (-104)
  115. #define UNZ_CRCERROR (-105)
  116. #define UNZ_CASESENSITIVE 1
  117. #define UNZ_NOTCASESENSITIVE 2
  118. #define UNZ_OSDEFAULTCASE 0
  119. extern int unzStringFileNameCompare (const char* fileName1, const char* fileName2, int iCaseSensitivity);
  120. /*
  121. Compare two filename (fileName1,fileName2).
  122. If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
  123. If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
  124. or strcasecmp)
  125. If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
  126. (like 1 on Unix, 2 on Windows)
  127. */
  128. extern unzFile unzOpen (const char *path);
  129. extern unzFile unzReOpen (const char* path, unzFile file);
  130. /*
  131. Open a Zip file. path contain the full pathname (by example,
  132. on a Windows NT computer "c:\\zlib\\zlib111.zip" or on an Unix computer
  133. "zlib/zlib111.zip".
  134. If the zipfile cannot be opened (file don't exist or in not valid), the
  135. return value is NULL.
  136. Else, the return value is a unzFile Handle, usable with other function
  137. of this unzip package.
  138. */
  139. extern int unzClose (unzFile file);
  140. /*
  141. Close a ZipFile opened with unzipOpen.
  142. If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
  143. these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
  144. return UNZ_OK if there is no problem. */
  145. extern int unzGetGlobalInfo (unzFile file, unz_global_info *pglobal_info);
  146. /*
  147. Write info about the ZipFile in the *pglobal_info structure.
  148. No preparation of the structure is needed
  149. return UNZ_OK if there is no problem. */
  150. extern int unzGetGlobalComment (unzFile file, char *szComment, unsigned long uSizeBuf);
  151. /*
  152. Get the global comment string of the ZipFile, in the szComment buffer.
  153. uSizeBuf is the size of the szComment buffer.
  154. return the number of unsigned char copied or an error code <0
  155. */
  156. /***************************************************************************/
  157. /* Unzip package allow you browse the directory of the zipfile */
  158. extern int unzGoToFirstFile (unzFile file);
  159. /*
  160. Set the current file of the zipfile to the first file.
  161. return UNZ_OK if there is no problem
  162. */
  163. extern int unzGoToNextFile (unzFile file);
  164. /*
  165. Set the current file of the zipfile to the next file.
  166. return UNZ_OK if there is no problem
  167. return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
  168. */
  169. extern int unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity);
  170. /*
  171. Try locate the file szFileName in the zipfile.
  172. For the iCaseSensitivity signification, see unzStringFileNameCompare
  173. return value :
  174. UNZ_OK if the file is found. It becomes the current file.
  175. UNZ_END_OF_LIST_OF_FILE if the file is not found
  176. */
  177. 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);
  178. /*
  179. Get Info about the current file
  180. if pfile_info!=NULL, the *pfile_info structure will contain somes info about
  181. the current file
  182. if szFileName!=NULL, the filemane string will be copied in szFileName
  183. (fileNameBufferSize is the size of the buffer)
  184. if extraField!=NULL, the extra field information will be copied in extraField
  185. (extraFieldBufferSize is the size of the buffer).
  186. This is the Central-header version of the extra field
  187. if szComment!=NULL, the comment string of the file will be copied in szComment
  188. (commentBufferSize is the size of the buffer)
  189. */
  190. /***************************************************************************/
  191. /* for reading the content of the current zipfile, you can open it, read data
  192. from it, and close it (you can close it before reading all the file)
  193. */
  194. extern int unzOpenCurrentFile (unzFile file);
  195. /*
  196. Open for reading data the current file in the zipfile.
  197. If there is no error, the return value is UNZ_OK.
  198. */
  199. extern int unzCloseCurrentFile (unzFile file);
  200. /*
  201. Close the file in zip opened with unzOpenCurrentFile
  202. Return UNZ_CRCERROR if all the file was read but the CRC is not good
  203. */
  204. extern int unzReadCurrentFile (unzFile file, void* buf, unsigned len);
  205. /*
  206. Read unsigned chars from the current file (opened by unzOpenCurrentFile)
  207. buf contain buffer where data must be copied
  208. len the size of buf.
  209. return the number of unsigned char copied if somes unsigned chars are copied
  210. return 0 if the end of file was reached
  211. return <0 with error code if there is an error
  212. (UNZ_ERRNO for IO error, or zLib error for uncompress error)
  213. */
  214. extern long unztell(unzFile file);
  215. /*
  216. Give the current position in uncompressed data
  217. */
  218. extern int unzeof (unzFile file);
  219. /*
  220. return 1 if the end of file was reached, 0 elsewhere
  221. */
  222. extern int unzGetLocalExtrafield (unzFile file, void* buf, unsigned len);
  223. /*
  224. Read extra field from the current file (opened by unzOpenCurrentFile)
  225. This is the local-header version of the extra field (sometimes, there is
  226. more info in the local-header version than in the central-header)
  227. if buf==NULL, it return the size of the local extra field
  228. if buf!=NULL, len is the size of the buffer, the extra header is copied in
  229. buf.
  230. the return value is the number of unsigned chars copied in buf, or (if <0)
  231. the error code
  232. */