zip.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. /* zip.h -- IO on .zip files using zlib
  2. Version 1.1, February 14h, 2010
  3. part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
  4. Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
  5. Modifications for Zip64 support
  6. Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
  7. For more info read MiniZip_info.txt
  8. ---------------------------------------------------------------------------
  9. Condition of use and distribution are the same than zlib :
  10. This software is provided 'as-is', without any express or implied
  11. warranty. In no event will the authors be held liable for any damages
  12. arising from the use of this software.
  13. Permission is granted to anyone to use this software for any purpose,
  14. including commercial applications, and to alter it and redistribute it
  15. freely, subject to the following restrictions:
  16. 1. The origin of this software must not be misrepresented; you must not
  17. claim that you wrote the original software. If you use this software
  18. in a product, an acknowledgment in the product documentation would be
  19. appreciated but is not required.
  20. 2. Altered source versions must be plainly marked as such, and must not be
  21. misrepresented as being the original software.
  22. 3. This notice may not be removed or altered from any source distribution.
  23. ---------------------------------------------------------------------------
  24. Changes
  25. See header of zip.h
  26. */
  27. #ifndef _zip12_H
  28. #define _zip12_H
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. //#define HAVE_BZIP2
  33. #ifndef _ZLIB_H
  34. #include "third_party/zlib/zlib.h"
  35. #endif
  36. #ifndef _ZLIBIOAPI_H
  37. #include "ioapi.h"
  38. #endif
  39. #ifdef HAVE_BZIP2
  40. #include "bzlib.h"
  41. #endif
  42. #define Z_BZIP2ED 12
  43. #if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
  44. /* like the STRICT of WIN32, we define a pointer that cannot be converted
  45. from (void*) without cast */
  46. typedef struct TagzipFile__ { int unused; } zipFile__;
  47. typedef zipFile__ *zipFile;
  48. #else
  49. typedef voidp zipFile;
  50. #endif
  51. #define ZIP_OK (0)
  52. #define ZIP_EOF (0)
  53. #define ZIP_ERRNO (Z_ERRNO)
  54. #define ZIP_PARAMERROR (-102)
  55. #define ZIP_BADZIPFILE (-103)
  56. #define ZIP_INTERNALERROR (-104)
  57. #ifndef DEF_MEM_LEVEL
  58. # if MAX_MEM_LEVEL >= 8
  59. # define DEF_MEM_LEVEL 8
  60. # else
  61. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  62. # endif
  63. #endif
  64. /* default memLevel */
  65. /* tm_zip contain date/time info */
  66. typedef struct tm_zip_s
  67. {
  68. uInt tm_sec; /* seconds after the minute - [0,59] */
  69. uInt tm_min; /* minutes after the hour - [0,59] */
  70. uInt tm_hour; /* hours since midnight - [0,23] */
  71. uInt tm_mday; /* day of the month - [1,31] */
  72. uInt tm_mon; /* months since January - [0,11] */
  73. uInt tm_year; /* years - [1980..2044] */
  74. } tm_zip;
  75. typedef struct
  76. {
  77. tm_zip tmz_date; /* date in understandable format */
  78. uLong dosDate; /* if dos_date == 0, tmu_date is used */
  79. /* uLong flag; */ /* general purpose bit flag 2 bytes */
  80. uLong internal_fa; /* internal file attributes 2 bytes */
  81. uLong external_fa; /* external file attributes 4 bytes */
  82. } zip_fileinfo;
  83. typedef const char* zipcharpc;
  84. #define APPEND_STATUS_CREATE (0)
  85. #define APPEND_STATUS_CREATEAFTER (1)
  86. #define APPEND_STATUS_ADDINZIP (2)
  87. extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append));
  88. extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append));
  89. /*
  90. Create a zipfile.
  91. pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
  92. an Unix computer "zlib/zlib113.zip".
  93. if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
  94. will be created at the end of the file.
  95. (useful if the file contain a self extractor code)
  96. if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
  97. add files in existing zip (be sure you don't add file that doesn't exist)
  98. If the zipfile cannot be opened, the return value is NULL.
  99. Else, the return value is a zipFile Handle, usable with other function
  100. of this zip package.
  101. */
  102. /* Note : there is no delete function into a zipfile.
  103. If you want delete file into a zipfile, you must open a zipfile, and create another
  104. Of couse, you can use RAW reading and writing to copy the file you did not want delte
  105. */
  106. extern zipFile ZEXPORT zipOpen2 OF((const char *pathname,
  107. int append,
  108. zipcharpc* globalcomment,
  109. zlib_filefunc_def* pzlib_filefunc_def));
  110. extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname,
  111. int append,
  112. zipcharpc* globalcomment,
  113. zlib_filefunc64_def* pzlib_filefunc_def));
  114. extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file,
  115. const char* filename,
  116. const zip_fileinfo* zipfi,
  117. const void* extrafield_local,
  118. uInt size_extrafield_local,
  119. const void* extrafield_global,
  120. uInt size_extrafield_global,
  121. const char* comment,
  122. int method,
  123. int level));
  124. extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file,
  125. const char* filename,
  126. const zip_fileinfo* zipfi,
  127. const void* extrafield_local,
  128. uInt size_extrafield_local,
  129. const void* extrafield_global,
  130. uInt size_extrafield_global,
  131. const char* comment,
  132. int method,
  133. int level,
  134. int zip64));
  135. /*
  136. Open a file in the ZIP for writing.
  137. filename : the filename in zip (if NULL, '-' without quote will be used
  138. *zipfi contain supplemental information
  139. if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
  140. contains the extrafield data the the local header
  141. if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
  142. contains the extrafield data the the local header
  143. if comment != NULL, comment contain the comment string
  144. method contain the compression method (0 for store, Z_DEFLATED for deflate)
  145. level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
  146. zip64 is set to 1 if a zip64 extended information block should be added to the local file header.
  147. this MUST be '1' if the uncompressed size is >= 0xffffffff.
  148. */
  149. extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file,
  150. const char* filename,
  151. const zip_fileinfo* zipfi,
  152. const void* extrafield_local,
  153. uInt size_extrafield_local,
  154. const void* extrafield_global,
  155. uInt size_extrafield_global,
  156. const char* comment,
  157. int method,
  158. int level,
  159. int raw));
  160. extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file,
  161. const char* filename,
  162. const zip_fileinfo* zipfi,
  163. const void* extrafield_local,
  164. uInt size_extrafield_local,
  165. const void* extrafield_global,
  166. uInt size_extrafield_global,
  167. const char* comment,
  168. int method,
  169. int level,
  170. int raw,
  171. int zip64));
  172. /*
  173. Same than zipOpenNewFileInZip, except if raw=1, we write raw file
  174. */
  175. extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file,
  176. const char* filename,
  177. const zip_fileinfo* zipfi,
  178. const void* extrafield_local,
  179. uInt size_extrafield_local,
  180. const void* extrafield_global,
  181. uInt size_extrafield_global,
  182. const char* comment,
  183. int method,
  184. int level,
  185. int raw,
  186. int windowBits,
  187. int memLevel,
  188. int strategy,
  189. const char* password,
  190. uLong crcForCrypting));
  191. extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file,
  192. const char* filename,
  193. const zip_fileinfo* zipfi,
  194. const void* extrafield_local,
  195. uInt size_extrafield_local,
  196. const void* extrafield_global,
  197. uInt size_extrafield_global,
  198. const char* comment,
  199. int method,
  200. int level,
  201. int raw,
  202. int windowBits,
  203. int memLevel,
  204. int strategy,
  205. const char* password,
  206. uLong crcForCrypting,
  207. int zip64
  208. ));
  209. /*
  210. Same than zipOpenNewFileInZip2, except
  211. windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
  212. password : crypting password (NULL for no crypting)
  213. crcForCrypting : crc of file to compress (needed for crypting)
  214. */
  215. extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file,
  216. const char* filename,
  217. const zip_fileinfo* zipfi,
  218. const void* extrafield_local,
  219. uInt size_extrafield_local,
  220. const void* extrafield_global,
  221. uInt size_extrafield_global,
  222. const char* comment,
  223. int method,
  224. int level,
  225. int raw,
  226. int windowBits,
  227. int memLevel,
  228. int strategy,
  229. const char* password,
  230. uLong crcForCrypting,
  231. uLong versionMadeBy,
  232. uLong flagBase
  233. ));
  234. extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file,
  235. const char* filename,
  236. const zip_fileinfo* zipfi,
  237. const void* extrafield_local,
  238. uInt size_extrafield_local,
  239. const void* extrafield_global,
  240. uInt size_extrafield_global,
  241. const char* comment,
  242. int method,
  243. int level,
  244. int raw,
  245. int windowBits,
  246. int memLevel,
  247. int strategy,
  248. const char* password,
  249. uLong crcForCrypting,
  250. uLong versionMadeBy,
  251. uLong flagBase,
  252. int zip64
  253. ));
  254. /*
  255. Same than zipOpenNewFileInZip4, except
  256. versionMadeBy : value for Version made by field
  257. flag : value for flag field (compression level info will be added)
  258. */
  259. extern int ZEXPORT zipWriteInFileInZip OF((zipFile file,
  260. const void* buf,
  261. unsigned len));
  262. /*
  263. Write data in the zipfile
  264. */
  265. extern int ZEXPORT zipCloseFileInZip OF((zipFile file));
  266. /*
  267. Close the current file in the zipfile
  268. */
  269. extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file,
  270. uLong uncompressed_size,
  271. uLong crc32));
  272. extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file,
  273. ZPOS64_T uncompressed_size,
  274. uLong crc32));
  275. /*
  276. Close the current file in the zipfile, for file opened with
  277. parameter raw=1 in zipOpenNewFileInZip2
  278. uncompressed_size and crc32 are value for the uncompressed size
  279. */
  280. extern int ZEXPORT zipClose OF((zipFile file,
  281. const char* global_comment));
  282. /*
  283. Close the zipfile
  284. */
  285. extern int ZEXPORT zipRemoveExtraInfoBlock OF((char* pData, int* dataLen, short sHeader));
  286. /*
  287. zipRemoveExtraInfoBlock - Added by Mathias Svensson
  288. Remove extra information block from a extra information data for the local file header or central directory header
  289. It is needed to remove ZIP64 extra information blocks when before data is written if using RAW mode.
  290. 0x0001 is the signature header for the ZIP64 extra information blocks
  291. usage.
  292. Remove ZIP64 Extra information from a central director extra field data
  293. zipRemoveExtraInfoBlock(pCenDirExtraFieldData, &nCenDirExtraFieldDataLen, 0x0001);
  294. Remove ZIP64 Extra information from a Local File Header extra field data
  295. zipRemoveExtraInfoBlock(pLocalHeaderExtraFieldData, &nLocalHeaderExtraFieldDataLen, 0x0001);
  296. */
  297. #ifdef __cplusplus
  298. }
  299. #endif
  300. #endif /* _zip64_H */