Fossil SCM

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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button