zip.h 15 KB

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