1*da0073e9SAndroid Build Coastguard Worker /* miniz.c 2.1.0 - public domain deflate/inflate, zlib-subset, ZIP reading/writing/appending, PNG writing 2*da0073e9SAndroid Build Coastguard Worker See "unlicense" statement at the end of this file. 3*da0073e9SAndroid Build Coastguard Worker Rich Geldreich <[email protected]>, last updated Oct. 13, 2013 4*da0073e9SAndroid Build Coastguard Worker Implements RFC 1950: http://www.ietf.org/rfc/rfc1950.txt and RFC 1951: http://www.ietf.org/rfc/rfc1951.txt 5*da0073e9SAndroid Build Coastguard Worker 6*da0073e9SAndroid Build Coastguard Worker Most API's defined in miniz.c are optional. For example, to disable the archive related functions just define 7*da0073e9SAndroid Build Coastguard Worker MINIZ_NO_ARCHIVE_APIS, or to get rid of all stdio usage define MINIZ_NO_STDIO (see the list below for more macros). 8*da0073e9SAndroid Build Coastguard Worker 9*da0073e9SAndroid Build Coastguard Worker * Low-level Deflate/Inflate implementation notes: 10*da0073e9SAndroid Build Coastguard Worker 11*da0073e9SAndroid Build Coastguard Worker Compression: Use the "tdefl" API's. The compressor supports raw, static, and dynamic blocks, lazy or 12*da0073e9SAndroid Build Coastguard Worker greedy parsing, match length filtering, RLE-only, and Huffman-only streams. It performs and compresses 13*da0073e9SAndroid Build Coastguard Worker approximately as well as zlib. 14*da0073e9SAndroid Build Coastguard Worker 15*da0073e9SAndroid Build Coastguard Worker Decompression: Use the "tinfl" API's. The entire decompressor is implemented as a single function 16*da0073e9SAndroid Build Coastguard Worker coroutine: see tinfl_decompress(). It supports decompression into a 32KB (or larger power of 2) wrapping buffer, or into a memory 17*da0073e9SAndroid Build Coastguard Worker block large enough to hold the entire file. 18*da0073e9SAndroid Build Coastguard Worker 19*da0073e9SAndroid Build Coastguard Worker The low-level tdefl/tinfl API's do not make any use of dynamic memory allocation. 20*da0073e9SAndroid Build Coastguard Worker 21*da0073e9SAndroid Build Coastguard Worker * zlib-style API notes: 22*da0073e9SAndroid Build Coastguard Worker 23*da0073e9SAndroid Build Coastguard Worker miniz.c implements a fairly large subset of zlib. There's enough functionality present for it to be a drop-in 24*da0073e9SAndroid Build Coastguard Worker zlib replacement in many apps: 25*da0073e9SAndroid Build Coastguard Worker The z_stream struct, optional memory allocation callbacks 26*da0073e9SAndroid Build Coastguard Worker deflateInit/deflateInit2/deflate/deflateReset/deflateEnd/deflateBound 27*da0073e9SAndroid Build Coastguard Worker inflateInit/inflateInit2/inflate/inflateReset/inflateEnd 28*da0073e9SAndroid Build Coastguard Worker compress, compress2, compressBound, uncompress 29*da0073e9SAndroid Build Coastguard Worker CRC-32, Adler-32 - Using modern, minimal code size, CPU cache friendly routines. 30*da0073e9SAndroid Build Coastguard Worker Supports raw deflate streams or standard zlib streams with adler-32 checking. 31*da0073e9SAndroid Build Coastguard Worker 32*da0073e9SAndroid Build Coastguard Worker Limitations: 33*da0073e9SAndroid Build Coastguard Worker The callback API's are not implemented yet. No support for gzip headers or zlib static dictionaries. 34*da0073e9SAndroid Build Coastguard Worker I've tried to closely emulate zlib's various flavors of stream flushing and return status codes, but 35*da0073e9SAndroid Build Coastguard Worker there are no guarantees that miniz.c pulls this off perfectly. 36*da0073e9SAndroid Build Coastguard Worker 37*da0073e9SAndroid Build Coastguard Worker * PNG writing: See the tdefl_write_image_to_png_file_in_memory() function, originally written by 38*da0073e9SAndroid Build Coastguard Worker Alex Evans. Supports 1-4 bytes/pixel images. 39*da0073e9SAndroid Build Coastguard Worker 40*da0073e9SAndroid Build Coastguard Worker * ZIP archive API notes: 41*da0073e9SAndroid Build Coastguard Worker 42*da0073e9SAndroid Build Coastguard Worker The ZIP archive API's where designed with simplicity and efficiency in mind, with just enough abstraction to 43*da0073e9SAndroid Build Coastguard Worker get the job done with minimal fuss. There are simple API's to retrieve file information, read files from 44*da0073e9SAndroid Build Coastguard Worker existing archives, create new archives, append new files to existing archives, or clone archive data from 45*da0073e9SAndroid Build Coastguard Worker one archive to another. It supports archives located in memory or the heap, on disk (using stdio.h), 46*da0073e9SAndroid Build Coastguard Worker or you can specify custom file read/write callbacks. 47*da0073e9SAndroid Build Coastguard Worker 48*da0073e9SAndroid Build Coastguard Worker - Archive reading: Just call this function to read a single file from a disk archive: 49*da0073e9SAndroid Build Coastguard Worker 50*da0073e9SAndroid Build Coastguard Worker void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, 51*da0073e9SAndroid Build Coastguard Worker size_t *pSize, mz_uint zip_flags); 52*da0073e9SAndroid Build Coastguard Worker 53*da0073e9SAndroid Build Coastguard Worker For more complex cases, use the "mz_zip_reader" functions. Upon opening an archive, the entire central 54*da0073e9SAndroid Build Coastguard Worker directory is located and read as-is into memory, and subsequent file access only occurs when reading individual files. 55*da0073e9SAndroid Build Coastguard Worker 56*da0073e9SAndroid Build Coastguard Worker - Archives file scanning: The simple way is to use this function to scan a loaded archive for a specific file: 57*da0073e9SAndroid Build Coastguard Worker 58*da0073e9SAndroid Build Coastguard Worker int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags); 59*da0073e9SAndroid Build Coastguard Worker 60*da0073e9SAndroid Build Coastguard Worker The locate operation can optionally check file comments too, which (as one example) can be used to identify 61*da0073e9SAndroid Build Coastguard Worker multiple versions of the same file in an archive. This function uses a simple linear search through the central 62*da0073e9SAndroid Build Coastguard Worker directory, so it's not very fast. 63*da0073e9SAndroid Build Coastguard Worker 64*da0073e9SAndroid Build Coastguard Worker Alternately, you can iterate through all the files in an archive (using mz_zip_reader_get_num_files()) and 65*da0073e9SAndroid Build Coastguard Worker retrieve detailed info on each file by calling mz_zip_reader_file_stat(). 66*da0073e9SAndroid Build Coastguard Worker 67*da0073e9SAndroid Build Coastguard Worker - Archive creation: Use the "mz_zip_writer" functions. The ZIP writer immediately writes compressed file data 68*da0073e9SAndroid Build Coastguard Worker to disk and builds an exact image of the central directory in memory. The central directory image is written 69*da0073e9SAndroid Build Coastguard Worker all at once at the end of the archive file when the archive is finalized. 70*da0073e9SAndroid Build Coastguard Worker 71*da0073e9SAndroid Build Coastguard Worker The archive writer can optionally align each file's local header and file data to any power of 2 alignment, 72*da0073e9SAndroid Build Coastguard Worker which can be useful when the archive will be read from optical media. Also, the writer supports placing 73*da0073e9SAndroid Build Coastguard Worker arbitrary data blobs at the very beginning of ZIP archives. Archives written using either feature are still 74*da0073e9SAndroid Build Coastguard Worker readable by any ZIP tool. 75*da0073e9SAndroid Build Coastguard Worker 76*da0073e9SAndroid Build Coastguard Worker - Archive appending: The simple way to add a single file to an archive is to call this function: 77*da0073e9SAndroid Build Coastguard Worker 78*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, 79*da0073e9SAndroid Build Coastguard Worker const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); 80*da0073e9SAndroid Build Coastguard Worker 81*da0073e9SAndroid Build Coastguard Worker The archive will be created if it doesn't already exist, otherwise it'll be appended to. 82*da0073e9SAndroid Build Coastguard Worker Note the appending is done in-place and is not an atomic operation, so if something goes wrong 83*da0073e9SAndroid Build Coastguard Worker during the operation it's possible the archive could be left without a central directory (although the local 84*da0073e9SAndroid Build Coastguard Worker file headers and file data will be fine, so the archive will be recoverable). 85*da0073e9SAndroid Build Coastguard Worker 86*da0073e9SAndroid Build Coastguard Worker For more complex archive modification scenarios: 87*da0073e9SAndroid Build Coastguard Worker 1. The safest way is to use a mz_zip_reader to read the existing archive, cloning only those bits you want to 88*da0073e9SAndroid Build Coastguard Worker preserve into a new archive using using the mz_zip_writer_add_from_zip_reader() function (which compiles the 89*da0073e9SAndroid Build Coastguard Worker compressed file data as-is). When you're done, delete the old archive and rename the newly written archive, and 90*da0073e9SAndroid Build Coastguard Worker you're done. This is safe but requires a bunch of temporary disk space or heap memory. 91*da0073e9SAndroid Build Coastguard Worker 92*da0073e9SAndroid Build Coastguard Worker 2. Or, you can convert an mz_zip_reader in-place to an mz_zip_writer using mz_zip_writer_init_from_reader(), 93*da0073e9SAndroid Build Coastguard Worker append new files as needed, then finalize the archive which will write an updated central directory to the 94*da0073e9SAndroid Build Coastguard Worker original archive. (This is basically what mz_zip_add_mem_to_archive_file_in_place() does.) There's a 95*da0073e9SAndroid Build Coastguard Worker possibility that the archive's central directory could be lost with this method if anything goes wrong, though. 96*da0073e9SAndroid Build Coastguard Worker 97*da0073e9SAndroid Build Coastguard Worker - ZIP archive support limitations: 98*da0073e9SAndroid Build Coastguard Worker No zip64 or spanning support. Extraction functions can only handle unencrypted, stored or deflated files. 99*da0073e9SAndroid Build Coastguard Worker Requires streams capable of seeking. 100*da0073e9SAndroid Build Coastguard Worker 101*da0073e9SAndroid Build Coastguard Worker * This is a header file library, like stb_image.c. To get only a header file, either cut and paste the 102*da0073e9SAndroid Build Coastguard Worker below header, or create miniz.h, #define MINIZ_HEADER_FILE_ONLY, and then include miniz.c from it. 103*da0073e9SAndroid Build Coastguard Worker 104*da0073e9SAndroid Build Coastguard Worker * Important: For best perf. be sure to customize the below macros for your target platform: 105*da0073e9SAndroid Build Coastguard Worker #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1 106*da0073e9SAndroid Build Coastguard Worker #define MINIZ_LITTLE_ENDIAN 1 107*da0073e9SAndroid Build Coastguard Worker #define MINIZ_HAS_64BIT_REGISTERS 1 108*da0073e9SAndroid Build Coastguard Worker 109*da0073e9SAndroid Build Coastguard Worker * On platforms using glibc, Be sure to "#define _LARGEFILE64_SOURCE 1" before including miniz.c to ensure miniz 110*da0073e9SAndroid Build Coastguard Worker uses the 64-bit variants: fopen64(), stat64(), etc. Otherwise you won't be able to process large files 111*da0073e9SAndroid Build Coastguard Worker (i.e. 32-bit stat() fails for me on files > 0x7FFFFFFF bytes). 112*da0073e9SAndroid Build Coastguard Worker */ 113*da0073e9SAndroid Build Coastguard Worker #pragma once 114*da0073e9SAndroid Build Coastguard Worker 115*da0073e9SAndroid Build Coastguard Worker 116*da0073e9SAndroid Build Coastguard Worker 117*da0073e9SAndroid Build Coastguard Worker 118*da0073e9SAndroid Build Coastguard Worker 119*da0073e9SAndroid Build Coastguard Worker /* Defines to completely disable specific portions of miniz.c: 120*da0073e9SAndroid Build Coastguard Worker If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl. */ 121*da0073e9SAndroid Build Coastguard Worker 122*da0073e9SAndroid Build Coastguard Worker /* Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O. */ 123*da0073e9SAndroid Build Coastguard Worker /*#define MINIZ_NO_STDIO */ 124*da0073e9SAndroid Build Coastguard Worker 125*da0073e9SAndroid Build Coastguard Worker /* If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or */ 126*da0073e9SAndroid Build Coastguard Worker /* get/set file times, and the C run-time funcs that get/set times won't be called. */ 127*da0073e9SAndroid Build Coastguard Worker /* The current downside is the times written to your archives will be from 1979. */ 128*da0073e9SAndroid Build Coastguard Worker #define MINIZ_NO_TIME 129*da0073e9SAndroid Build Coastguard Worker 130*da0073e9SAndroid Build Coastguard Worker /* Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's. */ 131*da0073e9SAndroid Build Coastguard Worker /*#define MINIZ_NO_ARCHIVE_APIS */ 132*da0073e9SAndroid Build Coastguard Worker 133*da0073e9SAndroid Build Coastguard Worker /* Define MINIZ_NO_ARCHIVE_WRITING_APIS to disable all writing related ZIP archive API's. */ 134*da0073e9SAndroid Build Coastguard Worker /*#define MINIZ_NO_ARCHIVE_WRITING_APIS */ 135*da0073e9SAndroid Build Coastguard Worker 136*da0073e9SAndroid Build Coastguard Worker /* Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's. */ 137*da0073e9SAndroid Build Coastguard Worker /*#define MINIZ_NO_ZLIB_APIS */ 138*da0073e9SAndroid Build Coastguard Worker 139*da0073e9SAndroid Build Coastguard Worker /* Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib. */ 140*da0073e9SAndroid Build Coastguard Worker #define MINIZ_NO_ZLIB_COMPATIBLE_NAMES 141*da0073e9SAndroid Build Coastguard Worker 142*da0073e9SAndroid Build Coastguard Worker /* Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc. 143*da0073e9SAndroid Build Coastguard Worker Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc 144*da0073e9SAndroid Build Coastguard Worker callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user 145*da0073e9SAndroid Build Coastguard Worker functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work. */ 146*da0073e9SAndroid Build Coastguard Worker /*#define MINIZ_NO_MALLOC */ 147*da0073e9SAndroid Build Coastguard Worker 148*da0073e9SAndroid Build Coastguard Worker #if defined(__TINYC__) && (defined(__linux) || defined(__linux__)) 149*da0073e9SAndroid Build Coastguard Worker /* TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux */ 150*da0073e9SAndroid Build Coastguard Worker #define MINIZ_NO_TIME 151*da0073e9SAndroid Build Coastguard Worker #endif 152*da0073e9SAndroid Build Coastguard Worker 153*da0073e9SAndroid Build Coastguard Worker #include <stddef.h> 154*da0073e9SAndroid Build Coastguard Worker 155*da0073e9SAndroid Build Coastguard Worker #if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS) 156*da0073e9SAndroid Build Coastguard Worker #include <time.h> 157*da0073e9SAndroid Build Coastguard Worker #endif 158*da0073e9SAndroid Build Coastguard Worker 159*da0073e9SAndroid Build Coastguard Worker #if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__) 160*da0073e9SAndroid Build Coastguard Worker /* MINIZ_X86_OR_X64_CPU is only used to help set the below macros. */ 161*da0073e9SAndroid Build Coastguard Worker #define MINIZ_X86_OR_X64_CPU 1 162*da0073e9SAndroid Build Coastguard Worker #else 163*da0073e9SAndroid Build Coastguard Worker #define MINIZ_X86_OR_X64_CPU 0 164*da0073e9SAndroid Build Coastguard Worker #endif 165*da0073e9SAndroid Build Coastguard Worker 166*da0073e9SAndroid Build Coastguard Worker #if (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU 167*da0073e9SAndroid Build Coastguard Worker /* Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian. */ 168*da0073e9SAndroid Build Coastguard Worker #define MINIZ_LITTLE_ENDIAN 1 169*da0073e9SAndroid Build Coastguard Worker #else 170*da0073e9SAndroid Build Coastguard Worker #define MINIZ_LITTLE_ENDIAN 0 171*da0073e9SAndroid Build Coastguard Worker #endif 172*da0073e9SAndroid Build Coastguard Worker 173*da0073e9SAndroid Build Coastguard Worker /* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES only if not set */ 174*da0073e9SAndroid Build Coastguard Worker #if !defined(MINIZ_USE_UNALIGNED_LOADS_AND_STORES) 175*da0073e9SAndroid Build Coastguard Worker #if MINIZ_X86_OR_X64_CPU 176*da0073e9SAndroid Build Coastguard Worker /* Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses. */ 177*da0073e9SAndroid Build Coastguard Worker /* zdevito: ASAN doesn't like unligned loads and stores, and -O3 optimizes the unoptimized code pattern away anyawy */ 178*da0073e9SAndroid Build Coastguard Worker #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0 179*da0073e9SAndroid Build Coastguard Worker /* zdevito: ASAN doesn't like unligned loads and stores, and -O3 optimizes the unoptimized code pattern away anyawy */ 180*da0073e9SAndroid Build Coastguard Worker /*#define MINIZ_UNALIGNED_USE_MEMCPY*/ 181*da0073e9SAndroid Build Coastguard Worker #else 182*da0073e9SAndroid Build Coastguard Worker #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 0 183*da0073e9SAndroid Build Coastguard Worker #endif 184*da0073e9SAndroid Build Coastguard Worker #endif 185*da0073e9SAndroid Build Coastguard Worker 186*da0073e9SAndroid Build Coastguard Worker #if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__) 187*da0073e9SAndroid Build Coastguard Worker /* Set MINIZ_HAS_64BIT_REGISTERS to 1 if operations on 64-bit integers are reasonably fast (and don't involve compiler generated calls to helper functions). */ 188*da0073e9SAndroid Build Coastguard Worker #define MINIZ_HAS_64BIT_REGISTERS 1 189*da0073e9SAndroid Build Coastguard Worker #else 190*da0073e9SAndroid Build Coastguard Worker #define MINIZ_HAS_64BIT_REGISTERS 0 191*da0073e9SAndroid Build Coastguard Worker #endif 192*da0073e9SAndroid Build Coastguard Worker 193*da0073e9SAndroid Build Coastguard Worker #ifdef __cplusplus 194*da0073e9SAndroid Build Coastguard Worker extern "C" { 195*da0073e9SAndroid Build Coastguard Worker #endif 196*da0073e9SAndroid Build Coastguard Worker 197*da0073e9SAndroid Build Coastguard Worker /* ------------------- zlib-style API Definitions. */ 198*da0073e9SAndroid Build Coastguard Worker 199*da0073e9SAndroid Build Coastguard Worker /* For more compatibility with zlib, miniz.c uses unsigned long for some parameters/struct members. Beware: mz_ulong can be either 32 or 64-bits! */ 200*da0073e9SAndroid Build Coastguard Worker typedef unsigned long mz_ulong; 201*da0073e9SAndroid Build Coastguard Worker 202*da0073e9SAndroid Build Coastguard Worker /* mz_free() internally uses the MZ_FREE() macro (which by default calls free() unless you've modified the MZ_MALLOC macro) to release a block allocated from the heap. */ 203*da0073e9SAndroid Build Coastguard Worker void mz_free(void *p); 204*da0073e9SAndroid Build Coastguard Worker 205*da0073e9SAndroid Build Coastguard Worker #define MZ_ADLER32_INIT (1) 206*da0073e9SAndroid Build Coastguard Worker /* mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL. */ 207*da0073e9SAndroid Build Coastguard Worker mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len); 208*da0073e9SAndroid Build Coastguard Worker 209*da0073e9SAndroid Build Coastguard Worker #define MZ_CRC32_INIT (0) 210*da0073e9SAndroid Build Coastguard Worker /* mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL. */ 211*da0073e9SAndroid Build Coastguard Worker mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len); 212*da0073e9SAndroid Build Coastguard Worker 213*da0073e9SAndroid Build Coastguard Worker /* Compression strategies. */ 214*da0073e9SAndroid Build Coastguard Worker enum 215*da0073e9SAndroid Build Coastguard Worker { 216*da0073e9SAndroid Build Coastguard Worker MZ_DEFAULT_STRATEGY = 0, 217*da0073e9SAndroid Build Coastguard Worker MZ_FILTERED = 1, 218*da0073e9SAndroid Build Coastguard Worker MZ_HUFFMAN_ONLY = 2, 219*da0073e9SAndroid Build Coastguard Worker MZ_RLE = 3, 220*da0073e9SAndroid Build Coastguard Worker MZ_FIXED = 4 221*da0073e9SAndroid Build Coastguard Worker }; 222*da0073e9SAndroid Build Coastguard Worker 223*da0073e9SAndroid Build Coastguard Worker /* Method */ 224*da0073e9SAndroid Build Coastguard Worker #define MZ_DEFLATED 8 225*da0073e9SAndroid Build Coastguard Worker 226*da0073e9SAndroid Build Coastguard Worker /* Heap allocation callbacks. 227*da0073e9SAndroid Build Coastguard Worker Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long. */ 228*da0073e9SAndroid Build Coastguard Worker typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size); 229*da0073e9SAndroid Build Coastguard Worker typedef void (*mz_free_func)(void *opaque, void *address); 230*da0073e9SAndroid Build Coastguard Worker typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size); 231*da0073e9SAndroid Build Coastguard Worker 232*da0073e9SAndroid Build Coastguard Worker /* Compression levels: 0-9 are the standard zlib-style levels, 10 is best possible compression (not zlib compatible, and may be very slow), MZ_DEFAULT_COMPRESSION=MZ_DEFAULT_LEVEL. */ 233*da0073e9SAndroid Build Coastguard Worker enum 234*da0073e9SAndroid Build Coastguard Worker { 235*da0073e9SAndroid Build Coastguard Worker MZ_NO_COMPRESSION = 0, 236*da0073e9SAndroid Build Coastguard Worker MZ_BEST_SPEED = 1, 237*da0073e9SAndroid Build Coastguard Worker MZ_BEST_COMPRESSION = 9, 238*da0073e9SAndroid Build Coastguard Worker MZ_UBER_COMPRESSION = 10, 239*da0073e9SAndroid Build Coastguard Worker MZ_DEFAULT_LEVEL = 6, 240*da0073e9SAndroid Build Coastguard Worker MZ_DEFAULT_COMPRESSION = -1 241*da0073e9SAndroid Build Coastguard Worker }; 242*da0073e9SAndroid Build Coastguard Worker 243*da0073e9SAndroid Build Coastguard Worker #define MZ_VERSION "10.1.0" 244*da0073e9SAndroid Build Coastguard Worker #define MZ_VERNUM 0xA100 245*da0073e9SAndroid Build Coastguard Worker #define MZ_VER_MAJOR 10 246*da0073e9SAndroid Build Coastguard Worker #define MZ_VER_MINOR 1 247*da0073e9SAndroid Build Coastguard Worker #define MZ_VER_REVISION 0 248*da0073e9SAndroid Build Coastguard Worker #define MZ_VER_SUBREVISION 0 249*da0073e9SAndroid Build Coastguard Worker 250*da0073e9SAndroid Build Coastguard Worker #ifndef MINIZ_NO_ZLIB_APIS 251*da0073e9SAndroid Build Coastguard Worker 252*da0073e9SAndroid Build Coastguard Worker /* Flush values. For typical usage you only need MZ_NO_FLUSH and MZ_FINISH. The other values are for advanced use (refer to the zlib docs). */ 253*da0073e9SAndroid Build Coastguard Worker enum 254*da0073e9SAndroid Build Coastguard Worker { 255*da0073e9SAndroid Build Coastguard Worker MZ_NO_FLUSH = 0, 256*da0073e9SAndroid Build Coastguard Worker MZ_PARTIAL_FLUSH = 1, 257*da0073e9SAndroid Build Coastguard Worker MZ_SYNC_FLUSH = 2, 258*da0073e9SAndroid Build Coastguard Worker MZ_FULL_FLUSH = 3, 259*da0073e9SAndroid Build Coastguard Worker MZ_FINISH = 4, 260*da0073e9SAndroid Build Coastguard Worker MZ_BLOCK = 5 261*da0073e9SAndroid Build Coastguard Worker }; 262*da0073e9SAndroid Build Coastguard Worker 263*da0073e9SAndroid Build Coastguard Worker /* Return status codes. MZ_PARAM_ERROR is non-standard. */ 264*da0073e9SAndroid Build Coastguard Worker enum 265*da0073e9SAndroid Build Coastguard Worker { 266*da0073e9SAndroid Build Coastguard Worker MZ_OK = 0, 267*da0073e9SAndroid Build Coastguard Worker MZ_STREAM_END = 1, 268*da0073e9SAndroid Build Coastguard Worker MZ_NEED_DICT = 2, 269*da0073e9SAndroid Build Coastguard Worker MZ_ERRNO = -1, 270*da0073e9SAndroid Build Coastguard Worker MZ_STREAM_ERROR = -2, 271*da0073e9SAndroid Build Coastguard Worker MZ_DATA_ERROR = -3, 272*da0073e9SAndroid Build Coastguard Worker MZ_MEM_ERROR = -4, 273*da0073e9SAndroid Build Coastguard Worker MZ_BUF_ERROR = -5, 274*da0073e9SAndroid Build Coastguard Worker MZ_VERSION_ERROR = -6, 275*da0073e9SAndroid Build Coastguard Worker MZ_PARAM_ERROR = -10000 276*da0073e9SAndroid Build Coastguard Worker }; 277*da0073e9SAndroid Build Coastguard Worker 278*da0073e9SAndroid Build Coastguard Worker /* Window bits */ 279*da0073e9SAndroid Build Coastguard Worker #define MZ_DEFAULT_WINDOW_BITS 15 280*da0073e9SAndroid Build Coastguard Worker 281*da0073e9SAndroid Build Coastguard Worker struct mz_internal_state; 282*da0073e9SAndroid Build Coastguard Worker 283*da0073e9SAndroid Build Coastguard Worker /* Compression/decompression stream struct. */ 284*da0073e9SAndroid Build Coastguard Worker typedef struct mz_stream_s 285*da0073e9SAndroid Build Coastguard Worker { 286*da0073e9SAndroid Build Coastguard Worker const unsigned char *next_in; /* pointer to next byte to read */ 287*da0073e9SAndroid Build Coastguard Worker unsigned int avail_in; /* number of bytes available at next_in */ 288*da0073e9SAndroid Build Coastguard Worker mz_ulong total_in; /* total number of bytes consumed so far */ 289*da0073e9SAndroid Build Coastguard Worker 290*da0073e9SAndroid Build Coastguard Worker unsigned char *next_out; /* pointer to next byte to write */ 291*da0073e9SAndroid Build Coastguard Worker unsigned int avail_out; /* number of bytes that can be written to next_out */ 292*da0073e9SAndroid Build Coastguard Worker mz_ulong total_out; /* total number of bytes produced so far */ 293*da0073e9SAndroid Build Coastguard Worker 294*da0073e9SAndroid Build Coastguard Worker char *msg; /* error msg (unused) */ 295*da0073e9SAndroid Build Coastguard Worker struct mz_internal_state *state; /* internal state, allocated by zalloc/zfree */ 296*da0073e9SAndroid Build Coastguard Worker 297*da0073e9SAndroid Build Coastguard Worker mz_alloc_func zalloc; /* optional heap allocation function (defaults to malloc) */ 298*da0073e9SAndroid Build Coastguard Worker mz_free_func zfree; /* optional heap free function (defaults to free) */ 299*da0073e9SAndroid Build Coastguard Worker void *opaque; /* heap alloc function user pointer */ 300*da0073e9SAndroid Build Coastguard Worker 301*da0073e9SAndroid Build Coastguard Worker int data_type; /* data_type (unused) */ 302*da0073e9SAndroid Build Coastguard Worker mz_ulong adler; /* adler32 of the source or uncompressed data */ 303*da0073e9SAndroid Build Coastguard Worker mz_ulong reserved; /* not used */ 304*da0073e9SAndroid Build Coastguard Worker } mz_stream; 305*da0073e9SAndroid Build Coastguard Worker 306*da0073e9SAndroid Build Coastguard Worker typedef mz_stream *mz_streamp; 307*da0073e9SAndroid Build Coastguard Worker 308*da0073e9SAndroid Build Coastguard Worker /* Returns the version string of miniz.c. */ 309*da0073e9SAndroid Build Coastguard Worker const char *mz_version(void); 310*da0073e9SAndroid Build Coastguard Worker 311*da0073e9SAndroid Build Coastguard Worker /* mz_deflateInit() initializes a compressor with default options: */ 312*da0073e9SAndroid Build Coastguard Worker /* Parameters: */ 313*da0073e9SAndroid Build Coastguard Worker /* pStream must point to an initialized mz_stream struct. */ 314*da0073e9SAndroid Build Coastguard Worker /* level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION]. */ 315*da0073e9SAndroid Build Coastguard Worker /* level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio. */ 316*da0073e9SAndroid Build Coastguard Worker /* (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.) */ 317*da0073e9SAndroid Build Coastguard Worker /* Return values: */ 318*da0073e9SAndroid Build Coastguard Worker /* MZ_OK on success. */ 319*da0073e9SAndroid Build Coastguard Worker /* MZ_STREAM_ERROR if the stream is bogus. */ 320*da0073e9SAndroid Build Coastguard Worker /* MZ_PARAM_ERROR if the input parameters are bogus. */ 321*da0073e9SAndroid Build Coastguard Worker /* MZ_MEM_ERROR on out of memory. */ 322*da0073e9SAndroid Build Coastguard Worker int mz_deflateInit(mz_streamp pStream, int level); 323*da0073e9SAndroid Build Coastguard Worker 324*da0073e9SAndroid Build Coastguard Worker /* mz_deflateInit2() is like mz_deflate(), except with more control: */ 325*da0073e9SAndroid Build Coastguard Worker /* Additional parameters: */ 326*da0073e9SAndroid Build Coastguard Worker /* method must be MZ_DEFLATED */ 327*da0073e9SAndroid Build Coastguard Worker /* window_bits must be MZ_DEFAULT_WINDOW_BITS (to wrap the deflate stream with zlib header/adler-32 footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate/no header or footer) */ 328*da0073e9SAndroid Build Coastguard Worker /* mem_level must be between [1, 9] (it's checked but ignored by miniz.c) */ 329*da0073e9SAndroid Build Coastguard Worker int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy); 330*da0073e9SAndroid Build Coastguard Worker 331*da0073e9SAndroid Build Coastguard Worker /* Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2(). */ 332*da0073e9SAndroid Build Coastguard Worker int mz_deflateReset(mz_streamp pStream); 333*da0073e9SAndroid Build Coastguard Worker 334*da0073e9SAndroid Build Coastguard Worker /* mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible. */ 335*da0073e9SAndroid Build Coastguard Worker /* Parameters: */ 336*da0073e9SAndroid Build Coastguard Worker /* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. */ 337*da0073e9SAndroid Build Coastguard Worker /* flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH. */ 338*da0073e9SAndroid Build Coastguard Worker /* Return values: */ 339*da0073e9SAndroid Build Coastguard Worker /* MZ_OK on success (when flushing, or if more input is needed but not available, and/or there's more output to be written but the output buffer is full). */ 340*da0073e9SAndroid Build Coastguard Worker /* MZ_STREAM_END if all input has been consumed and all output bytes have been written. Don't call mz_deflate() on the stream anymore. */ 341*da0073e9SAndroid Build Coastguard Worker /* MZ_STREAM_ERROR if the stream is bogus. */ 342*da0073e9SAndroid Build Coastguard Worker /* MZ_PARAM_ERROR if one of the parameters is invalid. */ 343*da0073e9SAndroid Build Coastguard Worker /* MZ_BUF_ERROR if no forward progress is possible because the input and/or output buffers are empty. (Fill up the input buffer or free up some output space and try again.) */ 344*da0073e9SAndroid Build Coastguard Worker int mz_deflate(mz_streamp pStream, int flush); 345*da0073e9SAndroid Build Coastguard Worker 346*da0073e9SAndroid Build Coastguard Worker /* mz_deflateEnd() deinitializes a compressor: */ 347*da0073e9SAndroid Build Coastguard Worker /* Return values: */ 348*da0073e9SAndroid Build Coastguard Worker /* MZ_OK on success. */ 349*da0073e9SAndroid Build Coastguard Worker /* MZ_STREAM_ERROR if the stream is bogus. */ 350*da0073e9SAndroid Build Coastguard Worker int mz_deflateEnd(mz_streamp pStream); 351*da0073e9SAndroid Build Coastguard Worker 352*da0073e9SAndroid Build Coastguard Worker /* mz_deflateBound() returns a (very) conservative upper bound on the amount of data that could be generated by deflate(), assuming flush is set to only MZ_NO_FLUSH or MZ_FINISH. */ 353*da0073e9SAndroid Build Coastguard Worker mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len); 354*da0073e9SAndroid Build Coastguard Worker 355*da0073e9SAndroid Build Coastguard Worker /* Single-call compression functions mz_compress() and mz_compress2(): */ 356*da0073e9SAndroid Build Coastguard Worker /* Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure. */ 357*da0073e9SAndroid Build Coastguard Worker int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len); 358*da0073e9SAndroid Build Coastguard Worker int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level); 359*da0073e9SAndroid Build Coastguard Worker 360*da0073e9SAndroid Build Coastguard Worker /* mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress(). */ 361*da0073e9SAndroid Build Coastguard Worker mz_ulong mz_compressBound(mz_ulong source_len); 362*da0073e9SAndroid Build Coastguard Worker 363*da0073e9SAndroid Build Coastguard Worker /* Initializes a decompressor. */ 364*da0073e9SAndroid Build Coastguard Worker int mz_inflateInit(mz_streamp pStream); 365*da0073e9SAndroid Build Coastguard Worker 366*da0073e9SAndroid Build Coastguard Worker /* mz_inflateInit2() is like mz_inflateInit() with an additional option that controls the window size and whether or not the stream has been wrapped with a zlib header/footer: */ 367*da0073e9SAndroid Build Coastguard Worker /* window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate). */ 368*da0073e9SAndroid Build Coastguard Worker int mz_inflateInit2(mz_streamp pStream, int window_bits); 369*da0073e9SAndroid Build Coastguard Worker 370*da0073e9SAndroid Build Coastguard Worker /* Quickly resets a compressor without having to reallocate anything. Same as calling mz_inflateEnd() followed by mz_inflateInit()/mz_inflateInit2(). */ 371*da0073e9SAndroid Build Coastguard Worker int mz_inflateReset(mz_streamp pStream); 372*da0073e9SAndroid Build Coastguard Worker 373*da0073e9SAndroid Build Coastguard Worker /* Decompresses the input stream to the output, consuming only as much of the input as needed, and writing as much to the output as possible. */ 374*da0073e9SAndroid Build Coastguard Worker /* Parameters: */ 375*da0073e9SAndroid Build Coastguard Worker /* pStream is the stream to read from and write to. You must initialize/update the next_in, avail_in, next_out, and avail_out members. */ 376*da0073e9SAndroid Build Coastguard Worker /* flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH. */ 377*da0073e9SAndroid Build Coastguard Worker /* On the first call, if flush is MZ_FINISH it's assumed the input and output buffers are both sized large enough to decompress the entire stream in a single call (this is slightly faster). */ 378*da0073e9SAndroid Build Coastguard Worker /* MZ_FINISH implies that there are no more source bytes available beside what's already in the input buffer, and that the output buffer is large enough to hold the rest of the decompressed data. */ 379*da0073e9SAndroid Build Coastguard Worker /* Return values: */ 380*da0073e9SAndroid Build Coastguard Worker /* MZ_OK on success. Either more input is needed but not available, and/or there's more output to be written but the output buffer is full. */ 381*da0073e9SAndroid Build Coastguard Worker /* MZ_STREAM_END if all needed input has been consumed and all output bytes have been written. For zlib streams, the adler-32 of the decompressed data has also been verified. */ 382*da0073e9SAndroid Build Coastguard Worker /* MZ_STREAM_ERROR if the stream is bogus. */ 383*da0073e9SAndroid Build Coastguard Worker /* MZ_DATA_ERROR if the deflate stream is invalid. */ 384*da0073e9SAndroid Build Coastguard Worker /* MZ_PARAM_ERROR if one of the parameters is invalid. */ 385*da0073e9SAndroid Build Coastguard Worker /* MZ_BUF_ERROR if no forward progress is possible because the input buffer is empty but the inflater needs more input to continue, or if the output buffer is not large enough. Call mz_inflate() again */ 386*da0073e9SAndroid Build Coastguard Worker /* with more input data, or with more room in the output buffer (except when using single call decompression, described above). */ 387*da0073e9SAndroid Build Coastguard Worker int mz_inflate(mz_streamp pStream, int flush); 388*da0073e9SAndroid Build Coastguard Worker 389*da0073e9SAndroid Build Coastguard Worker /* Deinitializes a decompressor. */ 390*da0073e9SAndroid Build Coastguard Worker int mz_inflateEnd(mz_streamp pStream); 391*da0073e9SAndroid Build Coastguard Worker 392*da0073e9SAndroid Build Coastguard Worker /* Single-call decompression. */ 393*da0073e9SAndroid Build Coastguard Worker /* Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. */ 394*da0073e9SAndroid Build Coastguard Worker int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len); 395*da0073e9SAndroid Build Coastguard Worker 396*da0073e9SAndroid Build Coastguard Worker /* Returns a string description of the specified error code, or NULL if the error code is invalid. */ 397*da0073e9SAndroid Build Coastguard Worker const char *mz_error(int err); 398*da0073e9SAndroid Build Coastguard Worker 399*da0073e9SAndroid Build Coastguard Worker /* Redefine zlib-compatible names to miniz equivalents, so miniz.c can be used as a drop-in replacement for the subset of zlib that miniz.c supports. */ 400*da0073e9SAndroid Build Coastguard Worker /* Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project. */ 401*da0073e9SAndroid Build Coastguard Worker #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES 402*da0073e9SAndroid Build Coastguard Worker typedef unsigned char Byte; 403*da0073e9SAndroid Build Coastguard Worker typedef unsigned int uInt; 404*da0073e9SAndroid Build Coastguard Worker typedef mz_ulong uLong; 405*da0073e9SAndroid Build Coastguard Worker typedef Byte Bytef; 406*da0073e9SAndroid Build Coastguard Worker typedef uInt uIntf; 407*da0073e9SAndroid Build Coastguard Worker typedef char charf; 408*da0073e9SAndroid Build Coastguard Worker typedef int intf; 409*da0073e9SAndroid Build Coastguard Worker typedef void *voidpf; 410*da0073e9SAndroid Build Coastguard Worker typedef uLong uLongf; 411*da0073e9SAndroid Build Coastguard Worker typedef void *voidp; 412*da0073e9SAndroid Build Coastguard Worker typedef void *const voidpc; 413*da0073e9SAndroid Build Coastguard Worker #define Z_NULL 0 414*da0073e9SAndroid Build Coastguard Worker #define Z_NO_FLUSH MZ_NO_FLUSH 415*da0073e9SAndroid Build Coastguard Worker #define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH 416*da0073e9SAndroid Build Coastguard Worker #define Z_SYNC_FLUSH MZ_SYNC_FLUSH 417*da0073e9SAndroid Build Coastguard Worker #define Z_FULL_FLUSH MZ_FULL_FLUSH 418*da0073e9SAndroid Build Coastguard Worker #define Z_FINISH MZ_FINISH 419*da0073e9SAndroid Build Coastguard Worker #define Z_BLOCK MZ_BLOCK 420*da0073e9SAndroid Build Coastguard Worker #define Z_OK MZ_OK 421*da0073e9SAndroid Build Coastguard Worker #define Z_STREAM_END MZ_STREAM_END 422*da0073e9SAndroid Build Coastguard Worker #define Z_NEED_DICT MZ_NEED_DICT 423*da0073e9SAndroid Build Coastguard Worker #define Z_ERRNO MZ_ERRNO 424*da0073e9SAndroid Build Coastguard Worker #define Z_STREAM_ERROR MZ_STREAM_ERROR 425*da0073e9SAndroid Build Coastguard Worker #define Z_DATA_ERROR MZ_DATA_ERROR 426*da0073e9SAndroid Build Coastguard Worker #define Z_MEM_ERROR MZ_MEM_ERROR 427*da0073e9SAndroid Build Coastguard Worker #define Z_BUF_ERROR MZ_BUF_ERROR 428*da0073e9SAndroid Build Coastguard Worker #define Z_VERSION_ERROR MZ_VERSION_ERROR 429*da0073e9SAndroid Build Coastguard Worker #define Z_PARAM_ERROR MZ_PARAM_ERROR 430*da0073e9SAndroid Build Coastguard Worker #define Z_NO_COMPRESSION MZ_NO_COMPRESSION 431*da0073e9SAndroid Build Coastguard Worker #define Z_BEST_SPEED MZ_BEST_SPEED 432*da0073e9SAndroid Build Coastguard Worker #define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION 433*da0073e9SAndroid Build Coastguard Worker #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION 434*da0073e9SAndroid Build Coastguard Worker #define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY 435*da0073e9SAndroid Build Coastguard Worker #define Z_FILTERED MZ_FILTERED 436*da0073e9SAndroid Build Coastguard Worker #define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY 437*da0073e9SAndroid Build Coastguard Worker #define Z_RLE MZ_RLE 438*da0073e9SAndroid Build Coastguard Worker #define Z_FIXED MZ_FIXED 439*da0073e9SAndroid Build Coastguard Worker #define Z_DEFLATED MZ_DEFLATED 440*da0073e9SAndroid Build Coastguard Worker #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS 441*da0073e9SAndroid Build Coastguard Worker #define alloc_func mz_alloc_func 442*da0073e9SAndroid Build Coastguard Worker #define free_func mz_free_func 443*da0073e9SAndroid Build Coastguard Worker #define internal_state mz_internal_state 444*da0073e9SAndroid Build Coastguard Worker #define z_stream mz_stream 445*da0073e9SAndroid Build Coastguard Worker #define deflateInit mz_deflateInit 446*da0073e9SAndroid Build Coastguard Worker #define deflateInit2 mz_deflateInit2 447*da0073e9SAndroid Build Coastguard Worker #define deflateReset mz_deflateReset 448*da0073e9SAndroid Build Coastguard Worker #define deflate mz_deflate 449*da0073e9SAndroid Build Coastguard Worker #define deflateEnd mz_deflateEnd 450*da0073e9SAndroid Build Coastguard Worker #define deflateBound mz_deflateBound 451*da0073e9SAndroid Build Coastguard Worker #define compress mz_compress 452*da0073e9SAndroid Build Coastguard Worker #define compress2 mz_compress2 453*da0073e9SAndroid Build Coastguard Worker #define compressBound mz_compressBound 454*da0073e9SAndroid Build Coastguard Worker #define inflateInit mz_inflateInit 455*da0073e9SAndroid Build Coastguard Worker #define inflateInit2 mz_inflateInit2 456*da0073e9SAndroid Build Coastguard Worker #define inflateReset mz_inflateReset 457*da0073e9SAndroid Build Coastguard Worker #define inflate mz_inflate 458*da0073e9SAndroid Build Coastguard Worker #define inflateEnd mz_inflateEnd 459*da0073e9SAndroid Build Coastguard Worker #define uncompress mz_uncompress 460*da0073e9SAndroid Build Coastguard Worker #define crc32 mz_crc32 461*da0073e9SAndroid Build Coastguard Worker #define adler32 mz_adler32 462*da0073e9SAndroid Build Coastguard Worker #define MAX_WBITS 15 463*da0073e9SAndroid Build Coastguard Worker #define MAX_MEM_LEVEL 9 464*da0073e9SAndroid Build Coastguard Worker #define zError mz_error 465*da0073e9SAndroid Build Coastguard Worker #define ZLIB_VERSION MZ_VERSION 466*da0073e9SAndroid Build Coastguard Worker #define ZLIB_VERNUM MZ_VERNUM 467*da0073e9SAndroid Build Coastguard Worker #define ZLIB_VER_MAJOR MZ_VER_MAJOR 468*da0073e9SAndroid Build Coastguard Worker #define ZLIB_VER_MINOR MZ_VER_MINOR 469*da0073e9SAndroid Build Coastguard Worker #define ZLIB_VER_REVISION MZ_VER_REVISION 470*da0073e9SAndroid Build Coastguard Worker #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION 471*da0073e9SAndroid Build Coastguard Worker #define zlibVersion mz_version 472*da0073e9SAndroid Build Coastguard Worker #define zlib_version mz_version() 473*da0073e9SAndroid Build Coastguard Worker #endif /* #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES */ 474*da0073e9SAndroid Build Coastguard Worker 475*da0073e9SAndroid Build Coastguard Worker #endif /* MINIZ_NO_ZLIB_APIS */ 476*da0073e9SAndroid Build Coastguard Worker 477*da0073e9SAndroid Build Coastguard Worker #ifdef __cplusplus 478*da0073e9SAndroid Build Coastguard Worker } 479*da0073e9SAndroid Build Coastguard Worker #endif 480*da0073e9SAndroid Build Coastguard Worker #pragma once 481*da0073e9SAndroid Build Coastguard Worker #include <assert.h> 482*da0073e9SAndroid Build Coastguard Worker #include <stdint.h> 483*da0073e9SAndroid Build Coastguard Worker #include <stdlib.h> 484*da0073e9SAndroid Build Coastguard Worker #include <string.h> 485*da0073e9SAndroid Build Coastguard Worker 486*da0073e9SAndroid Build Coastguard Worker /* ------------------- Types and macros */ 487*da0073e9SAndroid Build Coastguard Worker typedef unsigned char mz_uint8; 488*da0073e9SAndroid Build Coastguard Worker typedef signed short mz_int16; 489*da0073e9SAndroid Build Coastguard Worker typedef unsigned short mz_uint16; 490*da0073e9SAndroid Build Coastguard Worker typedef unsigned int mz_uint32; 491*da0073e9SAndroid Build Coastguard Worker typedef unsigned int mz_uint; 492*da0073e9SAndroid Build Coastguard Worker typedef int64_t mz_int64; 493*da0073e9SAndroid Build Coastguard Worker typedef uint64_t mz_uint64; 494*da0073e9SAndroid Build Coastguard Worker typedef int mz_bool; 495*da0073e9SAndroid Build Coastguard Worker 496*da0073e9SAndroid Build Coastguard Worker #define MZ_FALSE (0) 497*da0073e9SAndroid Build Coastguard Worker #define MZ_TRUE (1) 498*da0073e9SAndroid Build Coastguard Worker 499*da0073e9SAndroid Build Coastguard Worker /* Works around MSVC's spammy "warning C4127: conditional expression is constant" message. */ 500*da0073e9SAndroid Build Coastguard Worker #ifdef _MSC_VER 501*da0073e9SAndroid Build Coastguard Worker #define MZ_MACRO_END while (0, 0) 502*da0073e9SAndroid Build Coastguard Worker #else 503*da0073e9SAndroid Build Coastguard Worker #define MZ_MACRO_END while (0) 504*da0073e9SAndroid Build Coastguard Worker #endif 505*da0073e9SAndroid Build Coastguard Worker 506*da0073e9SAndroid Build Coastguard Worker #ifdef MINIZ_NO_STDIO 507*da0073e9SAndroid Build Coastguard Worker #define MZ_FILE void * 508*da0073e9SAndroid Build Coastguard Worker #else 509*da0073e9SAndroid Build Coastguard Worker #include <stdio.h> 510*da0073e9SAndroid Build Coastguard Worker #define MZ_FILE FILE 511*da0073e9SAndroid Build Coastguard Worker #endif /* #ifdef MINIZ_NO_STDIO */ 512*da0073e9SAndroid Build Coastguard Worker 513*da0073e9SAndroid Build Coastguard Worker #ifdef MINIZ_NO_TIME 514*da0073e9SAndroid Build Coastguard Worker typedef struct mz_dummy_time_t_tag 515*da0073e9SAndroid Build Coastguard Worker { 516*da0073e9SAndroid Build Coastguard Worker int m_dummy; 517*da0073e9SAndroid Build Coastguard Worker } mz_dummy_time_t; 518*da0073e9SAndroid Build Coastguard Worker #define MZ_TIME_T mz_dummy_time_t 519*da0073e9SAndroid Build Coastguard Worker #else 520*da0073e9SAndroid Build Coastguard Worker #define MZ_TIME_T time_t 521*da0073e9SAndroid Build Coastguard Worker #endif 522*da0073e9SAndroid Build Coastguard Worker 523*da0073e9SAndroid Build Coastguard Worker #define MZ_ASSERT(x) assert(x) 524*da0073e9SAndroid Build Coastguard Worker 525*da0073e9SAndroid Build Coastguard Worker #ifdef MINIZ_NO_MALLOC 526*da0073e9SAndroid Build Coastguard Worker #define MZ_MALLOC(x) NULL 527*da0073e9SAndroid Build Coastguard Worker #define MZ_FREE(x) (void)x, ((void)0) 528*da0073e9SAndroid Build Coastguard Worker #define MZ_REALLOC(p, x) NULL 529*da0073e9SAndroid Build Coastguard Worker #else 530*da0073e9SAndroid Build Coastguard Worker #define MZ_MALLOC(x) malloc(x) 531*da0073e9SAndroid Build Coastguard Worker #define MZ_FREE(x) free(x) 532*da0073e9SAndroid Build Coastguard Worker #define MZ_REALLOC(p, x) realloc(p, x) 533*da0073e9SAndroid Build Coastguard Worker #endif 534*da0073e9SAndroid Build Coastguard Worker 535*da0073e9SAndroid Build Coastguard Worker #define MZ_MAX(a, b) (((a) > (b)) ? (a) : (b)) 536*da0073e9SAndroid Build Coastguard Worker #define MZ_MIN(a, b) (((a) < (b)) ? (a) : (b)) 537*da0073e9SAndroid Build Coastguard Worker #define MZ_CLEAR_OBJ(obj) memset(&(obj), 0, sizeof(obj)) 538*da0073e9SAndroid Build Coastguard Worker 539*da0073e9SAndroid Build Coastguard Worker #if MINIZ_USE_UNALIGNED_LOADS_AND_STORES && MINIZ_LITTLE_ENDIAN 540*da0073e9SAndroid Build Coastguard Worker #define MZ_READ_LE16(p) *((const mz_uint16 *)(p)) 541*da0073e9SAndroid Build Coastguard Worker #define MZ_READ_LE32(p) *((const mz_uint32 *)(p)) 542*da0073e9SAndroid Build Coastguard Worker #else 543*da0073e9SAndroid Build Coastguard Worker #define MZ_READ_LE16(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U)) 544*da0073e9SAndroid Build Coastguard Worker #define MZ_READ_LE32(p) ((mz_uint32)(((const mz_uint8 *)(p))[0]) | ((mz_uint32)(((const mz_uint8 *)(p))[1]) << 8U) | ((mz_uint32)(((const mz_uint8 *)(p))[2]) << 16U) | ((mz_uint32)(((const mz_uint8 *)(p))[3]) << 24U)) 545*da0073e9SAndroid Build Coastguard Worker #endif 546*da0073e9SAndroid Build Coastguard Worker 547*da0073e9SAndroid Build Coastguard Worker #define MZ_READ_LE64(p) (((mz_uint64)MZ_READ_LE32(p)) | (((mz_uint64)MZ_READ_LE32((const mz_uint8 *)(p) + sizeof(mz_uint32))) << 32U)) 548*da0073e9SAndroid Build Coastguard Worker 549*da0073e9SAndroid Build Coastguard Worker #ifdef _MSC_VER 550*da0073e9SAndroid Build Coastguard Worker #define MZ_FORCEINLINE __forceinline 551*da0073e9SAndroid Build Coastguard Worker #elif defined(__GNUC__) 552*da0073e9SAndroid Build Coastguard Worker #define MZ_FORCEINLINE __inline__ __attribute__((__always_inline__)) 553*da0073e9SAndroid Build Coastguard Worker #else 554*da0073e9SAndroid Build Coastguard Worker #define MZ_FORCEINLINE inline 555*da0073e9SAndroid Build Coastguard Worker #endif 556*da0073e9SAndroid Build Coastguard Worker 557*da0073e9SAndroid Build Coastguard Worker #ifdef __cplusplus 558*da0073e9SAndroid Build Coastguard Worker extern "C" { 559*da0073e9SAndroid Build Coastguard Worker #endif 560*da0073e9SAndroid Build Coastguard Worker 561*da0073e9SAndroid Build Coastguard Worker extern void *miniz_def_alloc_func(void *opaque, size_t items, size_t size); 562*da0073e9SAndroid Build Coastguard Worker extern void miniz_def_free_func(void *opaque, void *address); 563*da0073e9SAndroid Build Coastguard Worker extern void *miniz_def_realloc_func(void *opaque, void *address, size_t items, size_t size); 564*da0073e9SAndroid Build Coastguard Worker 565*da0073e9SAndroid Build Coastguard Worker #define MZ_UINT16_MAX (0xFFFFU) 566*da0073e9SAndroid Build Coastguard Worker #define MZ_UINT32_MAX (0xFFFFFFFFU) 567*da0073e9SAndroid Build Coastguard Worker 568*da0073e9SAndroid Build Coastguard Worker #ifdef __cplusplus 569*da0073e9SAndroid Build Coastguard Worker } 570*da0073e9SAndroid Build Coastguard Worker #endif 571*da0073e9SAndroid Build Coastguard Worker #pragma once 572*da0073e9SAndroid Build Coastguard Worker 573*da0073e9SAndroid Build Coastguard Worker 574*da0073e9SAndroid Build Coastguard Worker #ifdef __cplusplus 575*da0073e9SAndroid Build Coastguard Worker extern "C" { 576*da0073e9SAndroid Build Coastguard Worker #endif 577*da0073e9SAndroid Build Coastguard Worker /* ------------------- Low-level Compression API Definitions */ 578*da0073e9SAndroid Build Coastguard Worker 579*da0073e9SAndroid Build Coastguard Worker /* Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently). */ 580*da0073e9SAndroid Build Coastguard Worker #define TDEFL_LESS_MEMORY 0 581*da0073e9SAndroid Build Coastguard Worker 582*da0073e9SAndroid Build Coastguard Worker /* tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search): */ 583*da0073e9SAndroid Build Coastguard Worker /* TDEFL_DEFAULT_MAX_PROBES: The compressor defaults to 128 dictionary probes per dictionary search. 0=Huffman only, 1=Huffman+LZ (fastest/crap compression), 4095=Huffman+LZ (slowest/best compression). */ 584*da0073e9SAndroid Build Coastguard Worker enum 585*da0073e9SAndroid Build Coastguard Worker { 586*da0073e9SAndroid Build Coastguard Worker TDEFL_HUFFMAN_ONLY = 0, 587*da0073e9SAndroid Build Coastguard Worker TDEFL_DEFAULT_MAX_PROBES = 128, 588*da0073e9SAndroid Build Coastguard Worker TDEFL_MAX_PROBES_MASK = 0xFFF 589*da0073e9SAndroid Build Coastguard Worker }; 590*da0073e9SAndroid Build Coastguard Worker 591*da0073e9SAndroid Build Coastguard Worker /* TDEFL_WRITE_ZLIB_HEADER: If set, the compressor outputs a zlib header before the deflate data, and the Adler-32 of the source data at the end. Otherwise, you'll get raw deflate data. */ 592*da0073e9SAndroid Build Coastguard Worker /* TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers). */ 593*da0073e9SAndroid Build Coastguard Worker /* TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing. */ 594*da0073e9SAndroid Build Coastguard Worker /* TDEFL_NONDETERMINISTIC_PARSING_FLAG: Enable to decrease the compressor's initialization time to the minimum, but the output may vary from run to run given the same input (depending on the contents of memory). */ 595*da0073e9SAndroid Build Coastguard Worker /* TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1) */ 596*da0073e9SAndroid Build Coastguard Worker /* TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled. */ 597*da0073e9SAndroid Build Coastguard Worker /* TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables. */ 598*da0073e9SAndroid Build Coastguard Worker /* TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks. */ 599*da0073e9SAndroid Build Coastguard Worker /* The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK). */ 600*da0073e9SAndroid Build Coastguard Worker enum 601*da0073e9SAndroid Build Coastguard Worker { 602*da0073e9SAndroid Build Coastguard Worker TDEFL_WRITE_ZLIB_HEADER = 0x01000, 603*da0073e9SAndroid Build Coastguard Worker TDEFL_COMPUTE_ADLER32 = 0x02000, 604*da0073e9SAndroid Build Coastguard Worker TDEFL_GREEDY_PARSING_FLAG = 0x04000, 605*da0073e9SAndroid Build Coastguard Worker TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000, 606*da0073e9SAndroid Build Coastguard Worker TDEFL_RLE_MATCHES = 0x10000, 607*da0073e9SAndroid Build Coastguard Worker TDEFL_FILTER_MATCHES = 0x20000, 608*da0073e9SAndroid Build Coastguard Worker TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000, 609*da0073e9SAndroid Build Coastguard Worker TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000 610*da0073e9SAndroid Build Coastguard Worker }; 611*da0073e9SAndroid Build Coastguard Worker 612*da0073e9SAndroid Build Coastguard Worker /* High level compression functions: */ 613*da0073e9SAndroid Build Coastguard Worker /* tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc(). */ 614*da0073e9SAndroid Build Coastguard Worker /* On entry: */ 615*da0073e9SAndroid Build Coastguard Worker /* pSrc_buf, src_buf_len: Pointer and size of source block to compress. */ 616*da0073e9SAndroid Build Coastguard Worker /* flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression. */ 617*da0073e9SAndroid Build Coastguard Worker /* On return: */ 618*da0073e9SAndroid Build Coastguard Worker /* Function returns a pointer to the compressed data, or NULL on failure. */ 619*da0073e9SAndroid Build Coastguard Worker /* *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data. */ 620*da0073e9SAndroid Build Coastguard Worker /* The caller must free() the returned block when it's no longer needed. */ 621*da0073e9SAndroid Build Coastguard Worker void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); 622*da0073e9SAndroid Build Coastguard Worker 623*da0073e9SAndroid Build Coastguard Worker /* tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory. */ 624*da0073e9SAndroid Build Coastguard Worker /* Returns 0 on failure. */ 625*da0073e9SAndroid Build Coastguard Worker size_t tdefl_compress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags); 626*da0073e9SAndroid Build Coastguard Worker 627*da0073e9SAndroid Build Coastguard Worker /* Compresses an image to a compressed PNG file in memory. */ 628*da0073e9SAndroid Build Coastguard Worker /* On entry: */ 629*da0073e9SAndroid Build Coastguard Worker /* pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4. */ 630*da0073e9SAndroid Build Coastguard Worker /* The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory. */ 631*da0073e9SAndroid Build Coastguard Worker /* level may range from [0,10], use MZ_NO_COMPRESSION, MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc. or a decent default is MZ_DEFAULT_LEVEL */ 632*da0073e9SAndroid Build Coastguard Worker /* If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps). */ 633*da0073e9SAndroid Build Coastguard Worker /* On return: */ 634*da0073e9SAndroid Build Coastguard Worker /* Function returns a pointer to the compressed data, or NULL on failure. */ 635*da0073e9SAndroid Build Coastguard Worker /* *pLen_out will be set to the size of the PNG image file. */ 636*da0073e9SAndroid Build Coastguard Worker /* The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed. */ 637*da0073e9SAndroid Build Coastguard Worker void *tdefl_write_image_to_png_file_in_memory_ex(const void *pImage, int w, int h, int num_chans, size_t *pLen_out, mz_uint level, mz_bool flip); 638*da0073e9SAndroid Build Coastguard Worker void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out); 639*da0073e9SAndroid Build Coastguard Worker 640*da0073e9SAndroid Build Coastguard Worker /* Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time. */ 641*da0073e9SAndroid Build Coastguard Worker typedef mz_bool (*tdefl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser); 642*da0073e9SAndroid Build Coastguard Worker 643*da0073e9SAndroid Build Coastguard Worker /* tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally. */ 644*da0073e9SAndroid Build Coastguard Worker mz_bool tdefl_compress_mem_to_output(const void *pBuf, size_t buf_len, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); 645*da0073e9SAndroid Build Coastguard Worker 646*da0073e9SAndroid Build Coastguard Worker enum 647*da0073e9SAndroid Build Coastguard Worker { 648*da0073e9SAndroid Build Coastguard Worker TDEFL_MAX_HUFF_TABLES = 3, 649*da0073e9SAndroid Build Coastguard Worker TDEFL_MAX_HUFF_SYMBOLS_0 = 288, 650*da0073e9SAndroid Build Coastguard Worker TDEFL_MAX_HUFF_SYMBOLS_1 = 32, 651*da0073e9SAndroid Build Coastguard Worker TDEFL_MAX_HUFF_SYMBOLS_2 = 19, 652*da0073e9SAndroid Build Coastguard Worker TDEFL_LZ_DICT_SIZE = 32768, 653*da0073e9SAndroid Build Coastguard Worker TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, 654*da0073e9SAndroid Build Coastguard Worker TDEFL_MIN_MATCH_LEN = 3, 655*da0073e9SAndroid Build Coastguard Worker TDEFL_MAX_MATCH_LEN = 258 656*da0073e9SAndroid Build Coastguard Worker }; 657*da0073e9SAndroid Build Coastguard Worker 658*da0073e9SAndroid Build Coastguard Worker /* TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes). */ 659*da0073e9SAndroid Build Coastguard Worker #if TDEFL_LESS_MEMORY 660*da0073e9SAndroid Build Coastguard Worker enum 661*da0073e9SAndroid Build Coastguard Worker { 662*da0073e9SAndroid Build Coastguard Worker TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024, 663*da0073e9SAndroid Build Coastguard Worker TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13) / 10, 664*da0073e9SAndroid Build Coastguard Worker TDEFL_MAX_HUFF_SYMBOLS = 288, 665*da0073e9SAndroid Build Coastguard Worker TDEFL_LZ_HASH_BITS = 12, 666*da0073e9SAndroid Build Coastguard Worker TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, 667*da0073e9SAndroid Build Coastguard Worker TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, 668*da0073e9SAndroid Build Coastguard Worker TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS 669*da0073e9SAndroid Build Coastguard Worker }; 670*da0073e9SAndroid Build Coastguard Worker #else 671*da0073e9SAndroid Build Coastguard Worker enum 672*da0073e9SAndroid Build Coastguard Worker { 673*da0073e9SAndroid Build Coastguard Worker TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024, 674*da0073e9SAndroid Build Coastguard Worker TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13) / 10, 675*da0073e9SAndroid Build Coastguard Worker TDEFL_MAX_HUFF_SYMBOLS = 288, 676*da0073e9SAndroid Build Coastguard Worker TDEFL_LZ_HASH_BITS = 15, 677*da0073e9SAndroid Build Coastguard Worker TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, 678*da0073e9SAndroid Build Coastguard Worker TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, 679*da0073e9SAndroid Build Coastguard Worker TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS 680*da0073e9SAndroid Build Coastguard Worker }; 681*da0073e9SAndroid Build Coastguard Worker #endif 682*da0073e9SAndroid Build Coastguard Worker 683*da0073e9SAndroid Build Coastguard Worker /* The low-level tdefl functions below may be used directly if the above helper functions aren't flexible enough. The low-level functions don't make any heap allocations, unlike the above helper functions. */ 684*da0073e9SAndroid Build Coastguard Worker typedef enum { 685*da0073e9SAndroid Build Coastguard Worker TDEFL_STATUS_BAD_PARAM = -2, 686*da0073e9SAndroid Build Coastguard Worker TDEFL_STATUS_PUT_BUF_FAILED = -1, 687*da0073e9SAndroid Build Coastguard Worker TDEFL_STATUS_OKAY = 0, 688*da0073e9SAndroid Build Coastguard Worker TDEFL_STATUS_DONE = 1 689*da0073e9SAndroid Build Coastguard Worker } tdefl_status; 690*da0073e9SAndroid Build Coastguard Worker 691*da0073e9SAndroid Build Coastguard Worker /* Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums */ 692*da0073e9SAndroid Build Coastguard Worker typedef enum { 693*da0073e9SAndroid Build Coastguard Worker TDEFL_NO_FLUSH = 0, 694*da0073e9SAndroid Build Coastguard Worker TDEFL_SYNC_FLUSH = 2, 695*da0073e9SAndroid Build Coastguard Worker TDEFL_FULL_FLUSH = 3, 696*da0073e9SAndroid Build Coastguard Worker TDEFL_FINISH = 4 697*da0073e9SAndroid Build Coastguard Worker } tdefl_flush; 698*da0073e9SAndroid Build Coastguard Worker 699*da0073e9SAndroid Build Coastguard Worker /* tdefl's compression state structure. */ 700*da0073e9SAndroid Build Coastguard Worker typedef struct 701*da0073e9SAndroid Build Coastguard Worker { 702*da0073e9SAndroid Build Coastguard Worker tdefl_put_buf_func_ptr m_pPut_buf_func; 703*da0073e9SAndroid Build Coastguard Worker void *m_pPut_buf_user; 704*da0073e9SAndroid Build Coastguard Worker mz_uint m_flags, m_max_probes[2]; 705*da0073e9SAndroid Build Coastguard Worker int m_greedy_parsing; 706*da0073e9SAndroid Build Coastguard Worker mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size; 707*da0073e9SAndroid Build Coastguard Worker mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end; 708*da0073e9SAndroid Build Coastguard Worker mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer; 709*da0073e9SAndroid Build Coastguard Worker mz_uint m_saved_match_dist, m_saved_match_len, m_saved_lit, m_output_flush_ofs, m_output_flush_remaining, m_finished, m_block_index, m_wants_to_finish; 710*da0073e9SAndroid Build Coastguard Worker tdefl_status m_prev_return_status; 711*da0073e9SAndroid Build Coastguard Worker const void *m_pIn_buf; 712*da0073e9SAndroid Build Coastguard Worker void *m_pOut_buf; 713*da0073e9SAndroid Build Coastguard Worker size_t *m_pIn_buf_size, *m_pOut_buf_size; 714*da0073e9SAndroid Build Coastguard Worker tdefl_flush m_flush; 715*da0073e9SAndroid Build Coastguard Worker const mz_uint8 *m_pSrc; 716*da0073e9SAndroid Build Coastguard Worker size_t m_src_buf_left, m_out_buf_ofs; 717*da0073e9SAndroid Build Coastguard Worker mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1]; 718*da0073e9SAndroid Build Coastguard Worker mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS]; 719*da0073e9SAndroid Build Coastguard Worker mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS]; 720*da0073e9SAndroid Build Coastguard Worker mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS]; 721*da0073e9SAndroid Build Coastguard Worker mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE]; 722*da0073e9SAndroid Build Coastguard Worker mz_uint16 m_next[TDEFL_LZ_DICT_SIZE]; 723*da0073e9SAndroid Build Coastguard Worker mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE]; 724*da0073e9SAndroid Build Coastguard Worker mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE]; 725*da0073e9SAndroid Build Coastguard Worker } tdefl_compressor; 726*da0073e9SAndroid Build Coastguard Worker 727*da0073e9SAndroid Build Coastguard Worker /* Initializes the compressor. */ 728*da0073e9SAndroid Build Coastguard Worker /* There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory. */ 729*da0073e9SAndroid Build Coastguard Worker /* pBut_buf_func: If NULL, output data will be supplied to the specified callback. In this case, the user should call the tdefl_compress_buffer() API for compression. */ 730*da0073e9SAndroid Build Coastguard Worker /* If pBut_buf_func is NULL the user should always call the tdefl_compress() API. */ 731*da0073e9SAndroid Build Coastguard Worker /* flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.) */ 732*da0073e9SAndroid Build Coastguard Worker tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); 733*da0073e9SAndroid Build Coastguard Worker 734*da0073e9SAndroid Build Coastguard Worker /* Compresses a block of data, consuming as much of the specified input buffer as possible, and writing as much compressed data to the specified output buffer as possible. */ 735*da0073e9SAndroid Build Coastguard Worker tdefl_status tdefl_compress(tdefl_compressor *d, const void *pIn_buf, size_t *pIn_buf_size, void *pOut_buf, size_t *pOut_buf_size, tdefl_flush flush); 736*da0073e9SAndroid Build Coastguard Worker 737*da0073e9SAndroid Build Coastguard Worker /* tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr. */ 738*da0073e9SAndroid Build Coastguard Worker /* tdefl_compress_buffer() always consumes the entire input buffer. */ 739*da0073e9SAndroid Build Coastguard Worker tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush); 740*da0073e9SAndroid Build Coastguard Worker 741*da0073e9SAndroid Build Coastguard Worker tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d); 742*da0073e9SAndroid Build Coastguard Worker mz_uint32 tdefl_get_adler32(tdefl_compressor *d); 743*da0073e9SAndroid Build Coastguard Worker 744*da0073e9SAndroid Build Coastguard Worker /* Create tdefl_compress() flags given zlib-style compression parameters. */ 745*da0073e9SAndroid Build Coastguard Worker /* level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files) */ 746*da0073e9SAndroid Build Coastguard Worker /* window_bits may be -15 (raw deflate) or 15 (zlib) */ 747*da0073e9SAndroid Build Coastguard Worker /* strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED */ 748*da0073e9SAndroid Build Coastguard Worker mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy); 749*da0073e9SAndroid Build Coastguard Worker 750*da0073e9SAndroid Build Coastguard Worker #ifndef MINIZ_NO_MALLOC 751*da0073e9SAndroid Build Coastguard Worker /* Allocate the tdefl_compressor structure in C so that */ 752*da0073e9SAndroid Build Coastguard Worker /* non-C language bindings to tdefl_ API don't need to worry about */ 753*da0073e9SAndroid Build Coastguard Worker /* structure size and allocation mechanism. */ 754*da0073e9SAndroid Build Coastguard Worker tdefl_compressor *tdefl_compressor_alloc(void); 755*da0073e9SAndroid Build Coastguard Worker void tdefl_compressor_free(tdefl_compressor *pComp); 756*da0073e9SAndroid Build Coastguard Worker #endif 757*da0073e9SAndroid Build Coastguard Worker 758*da0073e9SAndroid Build Coastguard Worker #ifdef __cplusplus 759*da0073e9SAndroid Build Coastguard Worker } 760*da0073e9SAndroid Build Coastguard Worker #endif 761*da0073e9SAndroid Build Coastguard Worker #pragma once 762*da0073e9SAndroid Build Coastguard Worker 763*da0073e9SAndroid Build Coastguard Worker /* ------------------- Low-level Decompression API Definitions */ 764*da0073e9SAndroid Build Coastguard Worker 765*da0073e9SAndroid Build Coastguard Worker #ifdef __cplusplus 766*da0073e9SAndroid Build Coastguard Worker extern "C" { 767*da0073e9SAndroid Build Coastguard Worker #endif 768*da0073e9SAndroid Build Coastguard Worker /* Decompression flags used by tinfl_decompress(). */ 769*da0073e9SAndroid Build Coastguard Worker /* TINFL_FLAG_PARSE_ZLIB_HEADER: If set, the input has a valid zlib header and ends with an adler32 checksum (it's a valid zlib stream). Otherwise, the input is a raw deflate stream. */ 770*da0073e9SAndroid Build Coastguard Worker /* TINFL_FLAG_HAS_MORE_INPUT: If set, there are more input bytes available beyond the end of the supplied input buffer. If clear, the input buffer contains all remaining input. */ 771*da0073e9SAndroid Build Coastguard Worker /* TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF: If set, the output buffer is large enough to hold the entire decompressed stream. If clear, the output buffer is at least the size of the dictionary (typically 32KB). */ 772*da0073e9SAndroid Build Coastguard Worker /* TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. */ 773*da0073e9SAndroid Build Coastguard Worker enum 774*da0073e9SAndroid Build Coastguard Worker { 775*da0073e9SAndroid Build Coastguard Worker TINFL_FLAG_PARSE_ZLIB_HEADER = 1, 776*da0073e9SAndroid Build Coastguard Worker TINFL_FLAG_HAS_MORE_INPUT = 2, 777*da0073e9SAndroid Build Coastguard Worker TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4, 778*da0073e9SAndroid Build Coastguard Worker TINFL_FLAG_COMPUTE_ADLER32 = 8 779*da0073e9SAndroid Build Coastguard Worker }; 780*da0073e9SAndroid Build Coastguard Worker 781*da0073e9SAndroid Build Coastguard Worker /* High level decompression functions: */ 782*da0073e9SAndroid Build Coastguard Worker /* tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc(). */ 783*da0073e9SAndroid Build Coastguard Worker /* On entry: */ 784*da0073e9SAndroid Build Coastguard Worker /* pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress. */ 785*da0073e9SAndroid Build Coastguard Worker /* On return: */ 786*da0073e9SAndroid Build Coastguard Worker /* Function returns a pointer to the decompressed data, or NULL on failure. */ 787*da0073e9SAndroid Build Coastguard Worker /* *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data. */ 788*da0073e9SAndroid Build Coastguard Worker /* The caller must call mz_free() on the returned block when it's no longer needed. */ 789*da0073e9SAndroid Build Coastguard Worker void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags); 790*da0073e9SAndroid Build Coastguard Worker 791*da0073e9SAndroid Build Coastguard Worker /* tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory. */ 792*da0073e9SAndroid Build Coastguard Worker /* Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success. */ 793*da0073e9SAndroid Build Coastguard Worker #define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1)) 794*da0073e9SAndroid Build Coastguard Worker size_t tinfl_decompress_mem_to_mem(void *pOut_buf, size_t out_buf_len, const void *pSrc_buf, size_t src_buf_len, int flags); 795*da0073e9SAndroid Build Coastguard Worker 796*da0073e9SAndroid Build Coastguard Worker /* tinfl_decompress_mem_to_callback() decompresses a block in memory to an internal 32KB buffer, and a user provided callback function will be called to flush the buffer. */ 797*da0073e9SAndroid Build Coastguard Worker /* Returns 1 on success or 0 on failure. */ 798*da0073e9SAndroid Build Coastguard Worker typedef int (*tinfl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser); 799*da0073e9SAndroid Build Coastguard Worker int tinfl_decompress_mem_to_callback(const void *pIn_buf, size_t *pIn_buf_size, tinfl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags); 800*da0073e9SAndroid Build Coastguard Worker 801*da0073e9SAndroid Build Coastguard Worker struct tinfl_decompressor_tag; 802*da0073e9SAndroid Build Coastguard Worker typedef struct tinfl_decompressor_tag tinfl_decompressor; 803*da0073e9SAndroid Build Coastguard Worker 804*da0073e9SAndroid Build Coastguard Worker #ifndef MINIZ_NO_MALLOC 805*da0073e9SAndroid Build Coastguard Worker /* Allocate the tinfl_decompressor structure in C so that */ 806*da0073e9SAndroid Build Coastguard Worker /* non-C language bindings to tinfl_ API don't need to worry about */ 807*da0073e9SAndroid Build Coastguard Worker /* structure size and allocation mechanism. */ 808*da0073e9SAndroid Build Coastguard Worker tinfl_decompressor *tinfl_decompressor_alloc(void); 809*da0073e9SAndroid Build Coastguard Worker void tinfl_decompressor_free(tinfl_decompressor *pDecomp); 810*da0073e9SAndroid Build Coastguard Worker #endif 811*da0073e9SAndroid Build Coastguard Worker 812*da0073e9SAndroid Build Coastguard Worker /* Max size of LZ dictionary. */ 813*da0073e9SAndroid Build Coastguard Worker #define TINFL_LZ_DICT_SIZE 32768 814*da0073e9SAndroid Build Coastguard Worker 815*da0073e9SAndroid Build Coastguard Worker /* Return status. */ 816*da0073e9SAndroid Build Coastguard Worker typedef enum { 817*da0073e9SAndroid Build Coastguard Worker /* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is indicating that no more are available. The compressed data */ 818*da0073e9SAndroid Build Coastguard Worker /* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input but this is a BAD sign (either the data is corrupted or you called it incorrectly). */ 819*da0073e9SAndroid Build Coastguard Worker /* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */ 820*da0073e9SAndroid Build Coastguard Worker TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS = -4, 821*da0073e9SAndroid Build Coastguard Worker 822*da0073e9SAndroid Build Coastguard Worker /* This flag indicates that one or more of the input parameters was obviously bogus. (You can try calling it again, but if you get this error the calling code is wrong.) */ 823*da0073e9SAndroid Build Coastguard Worker TINFL_STATUS_BAD_PARAM = -3, 824*da0073e9SAndroid Build Coastguard Worker 825*da0073e9SAndroid Build Coastguard Worker /* This flags indicate the inflator is finished but the adler32 check of the uncompressed data didn't match. If you call it again it'll return TINFL_STATUS_DONE. */ 826*da0073e9SAndroid Build Coastguard Worker TINFL_STATUS_ADLER32_MISMATCH = -2, 827*da0073e9SAndroid Build Coastguard Worker 828*da0073e9SAndroid Build Coastguard Worker /* This flags indicate the inflator has somehow failed (bad code, corrupted input, etc.). If you call it again without resetting via tinfl_init() it it'll just keep on returning the same status failure code. */ 829*da0073e9SAndroid Build Coastguard Worker TINFL_STATUS_FAILED = -1, 830*da0073e9SAndroid Build Coastguard Worker 831*da0073e9SAndroid Build Coastguard Worker /* Any status code less than TINFL_STATUS_DONE must indicate a failure. */ 832*da0073e9SAndroid Build Coastguard Worker 833*da0073e9SAndroid Build Coastguard Worker /* This flag indicates the inflator has returned every byte of uncompressed data that it can, has consumed every byte that it needed, has successfully reached the end of the deflate stream, and */ 834*da0073e9SAndroid Build Coastguard Worker /* if zlib headers and adler32 checking enabled that it has successfully checked the uncompressed data's adler32. If you call it again you'll just get TINFL_STATUS_DONE over and over again. */ 835*da0073e9SAndroid Build Coastguard Worker TINFL_STATUS_DONE = 0, 836*da0073e9SAndroid Build Coastguard Worker 837*da0073e9SAndroid Build Coastguard Worker /* This flag indicates the inflator MUST have more input data (even 1 byte) before it can make any more forward progress, or you need to clear the TINFL_FLAG_HAS_MORE_INPUT */ 838*da0073e9SAndroid Build Coastguard Worker /* flag on the next call if you don't have any more source data. If the source data was somehow corrupted it's also possible (but unlikely) for the inflator to keep on demanding input to */ 839*da0073e9SAndroid Build Coastguard Worker /* proceed, so be sure to properly set the TINFL_FLAG_HAS_MORE_INPUT flag. */ 840*da0073e9SAndroid Build Coastguard Worker TINFL_STATUS_NEEDS_MORE_INPUT = 1, 841*da0073e9SAndroid Build Coastguard Worker 842*da0073e9SAndroid Build Coastguard Worker /* This flag indicates the inflator definitely has 1 or more bytes of uncompressed data available, but it cannot write this data into the output buffer. */ 843*da0073e9SAndroid Build Coastguard Worker /* Note if the source compressed data was corrupted it's possible for the inflator to return a lot of uncompressed data to the caller. I've been assuming you know how much uncompressed data to expect */ 844*da0073e9SAndroid Build Coastguard Worker /* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure streaming scenarios where you have no idea how many bytes to expect this may not be possible */ 845*da0073e9SAndroid Build Coastguard Worker /* so I may need to add some code to address this. */ 846*da0073e9SAndroid Build Coastguard Worker TINFL_STATUS_HAS_MORE_OUTPUT = 2 847*da0073e9SAndroid Build Coastguard Worker } tinfl_status; 848*da0073e9SAndroid Build Coastguard Worker 849*da0073e9SAndroid Build Coastguard Worker /* Initializes the decompressor to its initial state. */ 850*da0073e9SAndroid Build Coastguard Worker #define tinfl_init(r) \ 851*da0073e9SAndroid Build Coastguard Worker do \ 852*da0073e9SAndroid Build Coastguard Worker { \ 853*da0073e9SAndroid Build Coastguard Worker (r)->m_state = 0; \ 854*da0073e9SAndroid Build Coastguard Worker } \ 855*da0073e9SAndroid Build Coastguard Worker MZ_MACRO_END 856*da0073e9SAndroid Build Coastguard Worker #define tinfl_get_adler32(r) (r)->m_check_adler32 857*da0073e9SAndroid Build Coastguard Worker 858*da0073e9SAndroid Build Coastguard Worker /* Main low-level decompressor coroutine function. This is the only function actually needed for decompression. All the other functions are just high-level helpers for improved usability. */ 859*da0073e9SAndroid Build Coastguard Worker /* This is a universal API, i.e. it can be used as a building block to build any desired higher level decompression API. In the limit case, it can be called once per every byte input or output. */ 860*da0073e9SAndroid Build Coastguard Worker tinfl_status tinfl_decompress(tinfl_decompressor *r, const mz_uint8 *pIn_buf_next, size_t *pIn_buf_size, mz_uint8 *pOut_buf_start, mz_uint8 *pOut_buf_next, size_t *pOut_buf_size, const mz_uint32 decomp_flags); 861*da0073e9SAndroid Build Coastguard Worker 862*da0073e9SAndroid Build Coastguard Worker /* Internal/private bits follow. */ 863*da0073e9SAndroid Build Coastguard Worker enum 864*da0073e9SAndroid Build Coastguard Worker { 865*da0073e9SAndroid Build Coastguard Worker TINFL_MAX_HUFF_TABLES = 3, 866*da0073e9SAndroid Build Coastguard Worker TINFL_MAX_HUFF_SYMBOLS_0 = 288, 867*da0073e9SAndroid Build Coastguard Worker TINFL_MAX_HUFF_SYMBOLS_1 = 32, 868*da0073e9SAndroid Build Coastguard Worker TINFL_MAX_HUFF_SYMBOLS_2 = 19, 869*da0073e9SAndroid Build Coastguard Worker TINFL_FAST_LOOKUP_BITS = 10, 870*da0073e9SAndroid Build Coastguard Worker TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS 871*da0073e9SAndroid Build Coastguard Worker }; 872*da0073e9SAndroid Build Coastguard Worker 873*da0073e9SAndroid Build Coastguard Worker typedef struct 874*da0073e9SAndroid Build Coastguard Worker { 875*da0073e9SAndroid Build Coastguard Worker mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0]; 876*da0073e9SAndroid Build Coastguard Worker mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2]; 877*da0073e9SAndroid Build Coastguard Worker } tinfl_huff_table; 878*da0073e9SAndroid Build Coastguard Worker 879*da0073e9SAndroid Build Coastguard Worker #if MINIZ_HAS_64BIT_REGISTERS 880*da0073e9SAndroid Build Coastguard Worker #define TINFL_USE_64BIT_BITBUF 1 881*da0073e9SAndroid Build Coastguard Worker #else 882*da0073e9SAndroid Build Coastguard Worker #define TINFL_USE_64BIT_BITBUF 0 883*da0073e9SAndroid Build Coastguard Worker #endif 884*da0073e9SAndroid Build Coastguard Worker 885*da0073e9SAndroid Build Coastguard Worker #if TINFL_USE_64BIT_BITBUF 886*da0073e9SAndroid Build Coastguard Worker typedef mz_uint64 tinfl_bit_buf_t; 887*da0073e9SAndroid Build Coastguard Worker #define TINFL_BITBUF_SIZE (64) 888*da0073e9SAndroid Build Coastguard Worker #else 889*da0073e9SAndroid Build Coastguard Worker typedef mz_uint32 tinfl_bit_buf_t; 890*da0073e9SAndroid Build Coastguard Worker #define TINFL_BITBUF_SIZE (32) 891*da0073e9SAndroid Build Coastguard Worker #endif 892*da0073e9SAndroid Build Coastguard Worker 893*da0073e9SAndroid Build Coastguard Worker struct tinfl_decompressor_tag 894*da0073e9SAndroid Build Coastguard Worker { 895*da0073e9SAndroid Build Coastguard Worker mz_uint32 m_state, m_num_bits, m_zhdr0, m_zhdr1, m_z_adler32, m_final, m_type, m_check_adler32, m_dist, m_counter, m_num_extra, m_table_sizes[TINFL_MAX_HUFF_TABLES]; 896*da0073e9SAndroid Build Coastguard Worker tinfl_bit_buf_t m_bit_buf; 897*da0073e9SAndroid Build Coastguard Worker size_t m_dist_from_out_buf_start; 898*da0073e9SAndroid Build Coastguard Worker tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES]; 899*da0073e9SAndroid Build Coastguard Worker mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137]; 900*da0073e9SAndroid Build Coastguard Worker }; 901*da0073e9SAndroid Build Coastguard Worker 902*da0073e9SAndroid Build Coastguard Worker #ifdef __cplusplus 903*da0073e9SAndroid Build Coastguard Worker } 904*da0073e9SAndroid Build Coastguard Worker #endif 905*da0073e9SAndroid Build Coastguard Worker 906*da0073e9SAndroid Build Coastguard Worker #pragma once 907*da0073e9SAndroid Build Coastguard Worker 908*da0073e9SAndroid Build Coastguard Worker 909*da0073e9SAndroid Build Coastguard Worker /* ------------------- ZIP archive reading/writing */ 910*da0073e9SAndroid Build Coastguard Worker 911*da0073e9SAndroid Build Coastguard Worker #ifndef MINIZ_NO_ARCHIVE_APIS 912*da0073e9SAndroid Build Coastguard Worker 913*da0073e9SAndroid Build Coastguard Worker #ifdef __cplusplus 914*da0073e9SAndroid Build Coastguard Worker extern "C" { 915*da0073e9SAndroid Build Coastguard Worker #endif 916*da0073e9SAndroid Build Coastguard Worker 917*da0073e9SAndroid Build Coastguard Worker enum 918*da0073e9SAndroid Build Coastguard Worker { 919*da0073e9SAndroid Build Coastguard Worker /* Note: These enums can be reduced as needed to save memory or stack space - they are pretty conservative. */ 920*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_MAX_IO_BUF_SIZE = 64 * 1024, 921*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 512, 922*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 512 923*da0073e9SAndroid Build Coastguard Worker }; 924*da0073e9SAndroid Build Coastguard Worker 925*da0073e9SAndroid Build Coastguard Worker typedef struct 926*da0073e9SAndroid Build Coastguard Worker { 927*da0073e9SAndroid Build Coastguard Worker /* Central directory file index. */ 928*da0073e9SAndroid Build Coastguard Worker mz_uint32 m_file_index; 929*da0073e9SAndroid Build Coastguard Worker 930*da0073e9SAndroid Build Coastguard Worker /* Byte offset of this entry in the archive's central directory. Note we currently only support up to UINT_MAX or less bytes in the central dir. */ 931*da0073e9SAndroid Build Coastguard Worker mz_uint64 m_central_dir_ofs; 932*da0073e9SAndroid Build Coastguard Worker 933*da0073e9SAndroid Build Coastguard Worker /* These fields are copied directly from the zip's central dir. */ 934*da0073e9SAndroid Build Coastguard Worker mz_uint16 m_version_made_by; 935*da0073e9SAndroid Build Coastguard Worker mz_uint16 m_version_needed; 936*da0073e9SAndroid Build Coastguard Worker mz_uint16 m_bit_flag; 937*da0073e9SAndroid Build Coastguard Worker mz_uint16 m_method; 938*da0073e9SAndroid Build Coastguard Worker 939*da0073e9SAndroid Build Coastguard Worker #ifndef MINIZ_NO_TIME 940*da0073e9SAndroid Build Coastguard Worker MZ_TIME_T m_time; 941*da0073e9SAndroid Build Coastguard Worker #endif 942*da0073e9SAndroid Build Coastguard Worker 943*da0073e9SAndroid Build Coastguard Worker /* CRC-32 of uncompressed data. */ 944*da0073e9SAndroid Build Coastguard Worker mz_uint32 m_crc32; 945*da0073e9SAndroid Build Coastguard Worker 946*da0073e9SAndroid Build Coastguard Worker /* File's compressed size. */ 947*da0073e9SAndroid Build Coastguard Worker mz_uint64 m_comp_size; 948*da0073e9SAndroid Build Coastguard Worker 949*da0073e9SAndroid Build Coastguard Worker /* File's uncompressed size. Note, I've seen some old archives where directory entries had 512 bytes for their uncompressed sizes, but when you try to unpack them you actually get 0 bytes. */ 950*da0073e9SAndroid Build Coastguard Worker mz_uint64 m_uncomp_size; 951*da0073e9SAndroid Build Coastguard Worker 952*da0073e9SAndroid Build Coastguard Worker /* Zip internal and external file attributes. */ 953*da0073e9SAndroid Build Coastguard Worker mz_uint16 m_internal_attr; 954*da0073e9SAndroid Build Coastguard Worker mz_uint32 m_external_attr; 955*da0073e9SAndroid Build Coastguard Worker 956*da0073e9SAndroid Build Coastguard Worker /* Entry's local header file offset in bytes. */ 957*da0073e9SAndroid Build Coastguard Worker mz_uint64 m_local_header_ofs; 958*da0073e9SAndroid Build Coastguard Worker 959*da0073e9SAndroid Build Coastguard Worker /* Size of comment in bytes. */ 960*da0073e9SAndroid Build Coastguard Worker mz_uint32 m_comment_size; 961*da0073e9SAndroid Build Coastguard Worker 962*da0073e9SAndroid Build Coastguard Worker /* MZ_TRUE if the entry appears to be a directory. */ 963*da0073e9SAndroid Build Coastguard Worker mz_bool m_is_directory; 964*da0073e9SAndroid Build Coastguard Worker 965*da0073e9SAndroid Build Coastguard Worker /* MZ_TRUE if the entry uses encryption/strong encryption (which miniz_zip doesn't support) */ 966*da0073e9SAndroid Build Coastguard Worker mz_bool m_is_encrypted; 967*da0073e9SAndroid Build Coastguard Worker 968*da0073e9SAndroid Build Coastguard Worker /* MZ_TRUE if the file is not encrypted, a patch file, and if it uses a compression method we support. */ 969*da0073e9SAndroid Build Coastguard Worker mz_bool m_is_supported; 970*da0073e9SAndroid Build Coastguard Worker 971*da0073e9SAndroid Build Coastguard Worker /* Filename. If string ends in '/' it's a subdirectory entry. */ 972*da0073e9SAndroid Build Coastguard Worker /* Guaranteed to be zero terminated, may be truncated to fit. */ 973*da0073e9SAndroid Build Coastguard Worker char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE]; 974*da0073e9SAndroid Build Coastguard Worker 975*da0073e9SAndroid Build Coastguard Worker /* Comment field. */ 976*da0073e9SAndroid Build Coastguard Worker /* Guaranteed to be zero terminated, may be truncated to fit. */ 977*da0073e9SAndroid Build Coastguard Worker char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE]; 978*da0073e9SAndroid Build Coastguard Worker 979*da0073e9SAndroid Build Coastguard Worker } mz_zip_archive_file_stat; 980*da0073e9SAndroid Build Coastguard Worker 981*da0073e9SAndroid Build Coastguard Worker typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n); 982*da0073e9SAndroid Build Coastguard Worker typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n); 983*da0073e9SAndroid Build Coastguard Worker typedef mz_bool (*mz_file_needs_keepalive)(void *pOpaque); 984*da0073e9SAndroid Build Coastguard Worker 985*da0073e9SAndroid Build Coastguard Worker struct mz_zip_internal_state_tag; 986*da0073e9SAndroid Build Coastguard Worker typedef struct mz_zip_internal_state_tag mz_zip_internal_state; 987*da0073e9SAndroid Build Coastguard Worker 988*da0073e9SAndroid Build Coastguard Worker typedef enum { 989*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_MODE_INVALID = 0, 990*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_MODE_READING = 1, 991*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_MODE_WRITING = 2, 992*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3 993*da0073e9SAndroid Build Coastguard Worker } mz_zip_mode; 994*da0073e9SAndroid Build Coastguard Worker 995*da0073e9SAndroid Build Coastguard Worker typedef enum { 996*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100, 997*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FLAG_IGNORE_PATH = 0x0200, 998*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400, 999*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800, 1000*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FLAG_VALIDATE_LOCATE_FILE_FLAG = 0x1000, /* if enabled, mz_zip_reader_locate_file() will be called on each file as its validated to ensure the func finds the file in the central dir (intended for testing) */ 1001*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY = 0x2000, /* validate the local headers, but don't decompress the entire file and check the crc32 */ 1002*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FLAG_WRITE_ZIP64 = 0x4000, /* always use the zip64 file format, instead of the original zip file format with automatic switch to zip64. Use as flags parameter with mz_zip_writer_init*_v2 */ 1003*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FLAG_WRITE_ALLOW_READING = 0x8000, 1004*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FLAG_ASCII_FILENAME = 0x10000 1005*da0073e9SAndroid Build Coastguard Worker } mz_zip_flags; 1006*da0073e9SAndroid Build Coastguard Worker 1007*da0073e9SAndroid Build Coastguard Worker typedef enum { 1008*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_TYPE_INVALID = 0, 1009*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_TYPE_USER, 1010*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_TYPE_MEMORY, 1011*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_TYPE_HEAP, 1012*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_TYPE_FILE, 1013*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_TYPE_CFILE, 1014*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_TOTAL_TYPES 1015*da0073e9SAndroid Build Coastguard Worker } mz_zip_type; 1016*da0073e9SAndroid Build Coastguard Worker 1017*da0073e9SAndroid Build Coastguard Worker /* miniz error codes. Be sure to update mz_zip_get_error_string() if you add or modify this enum. */ 1018*da0073e9SAndroid Build Coastguard Worker typedef enum { 1019*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_NO_ERROR = 0, 1020*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_UNDEFINED_ERROR, 1021*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_TOO_MANY_FILES, 1022*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FILE_TOO_LARGE, 1023*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_UNSUPPORTED_METHOD, 1024*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_UNSUPPORTED_ENCRYPTION, 1025*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_UNSUPPORTED_FEATURE, 1026*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FAILED_FINDING_CENTRAL_DIR, 1027*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_NOT_AN_ARCHIVE, 1028*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_INVALID_HEADER_OR_CORRUPTED, 1029*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_UNSUPPORTED_MULTIDISK, 1030*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_DECOMPRESSION_FAILED, 1031*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_COMPRESSION_FAILED, 1032*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_UNEXPECTED_DECOMPRESSED_SIZE, 1033*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_CRC_CHECK_FAILED, 1034*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_UNSUPPORTED_CDIR_SIZE, 1035*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_ALLOC_FAILED, 1036*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FILE_OPEN_FAILED, 1037*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FILE_CREATE_FAILED, 1038*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FILE_WRITE_FAILED, 1039*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FILE_READ_FAILED, 1040*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FILE_CLOSE_FAILED, 1041*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FILE_SEEK_FAILED, 1042*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FILE_STAT_FAILED, 1043*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_INVALID_PARAMETER, 1044*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_INVALID_FILENAME, 1045*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_BUF_TOO_SMALL, 1046*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_INTERNAL_ERROR, 1047*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_FILE_NOT_FOUND, 1048*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_ARCHIVE_TOO_LARGE, 1049*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_VALIDATION_FAILED, 1050*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_WRITE_CALLBACK_FAILED, 1051*da0073e9SAndroid Build Coastguard Worker MZ_ZIP_TOTAL_ERRORS 1052*da0073e9SAndroid Build Coastguard Worker } mz_zip_error; 1053*da0073e9SAndroid Build Coastguard Worker 1054*da0073e9SAndroid Build Coastguard Worker typedef struct mz_zip_archive /* note: added name so it can be forward declared */ 1055*da0073e9SAndroid Build Coastguard Worker { 1056*da0073e9SAndroid Build Coastguard Worker mz_uint64 m_archive_size; 1057*da0073e9SAndroid Build Coastguard Worker mz_uint64 m_central_directory_file_ofs; 1058*da0073e9SAndroid Build Coastguard Worker 1059*da0073e9SAndroid Build Coastguard Worker /* We only support up to UINT32_MAX files in zip64 mode. */ 1060*da0073e9SAndroid Build Coastguard Worker mz_uint32 m_total_files; 1061*da0073e9SAndroid Build Coastguard Worker mz_zip_mode m_zip_mode; 1062*da0073e9SAndroid Build Coastguard Worker mz_zip_type m_zip_type; 1063*da0073e9SAndroid Build Coastguard Worker mz_zip_error m_last_error; 1064*da0073e9SAndroid Build Coastguard Worker 1065*da0073e9SAndroid Build Coastguard Worker mz_uint64 m_file_offset_alignment; 1066*da0073e9SAndroid Build Coastguard Worker 1067*da0073e9SAndroid Build Coastguard Worker mz_alloc_func m_pAlloc; 1068*da0073e9SAndroid Build Coastguard Worker mz_free_func m_pFree; 1069*da0073e9SAndroid Build Coastguard Worker mz_realloc_func m_pRealloc; 1070*da0073e9SAndroid Build Coastguard Worker void *m_pAlloc_opaque; 1071*da0073e9SAndroid Build Coastguard Worker 1072*da0073e9SAndroid Build Coastguard Worker mz_file_read_func m_pRead; 1073*da0073e9SAndroid Build Coastguard Worker mz_file_write_func m_pWrite; 1074*da0073e9SAndroid Build Coastguard Worker mz_file_needs_keepalive m_pNeeds_keepalive; 1075*da0073e9SAndroid Build Coastguard Worker void *m_pIO_opaque; 1076*da0073e9SAndroid Build Coastguard Worker 1077*da0073e9SAndroid Build Coastguard Worker mz_zip_internal_state *m_pState; 1078*da0073e9SAndroid Build Coastguard Worker 1079*da0073e9SAndroid Build Coastguard Worker } mz_zip_archive; 1080*da0073e9SAndroid Build Coastguard Worker 1081*da0073e9SAndroid Build Coastguard Worker typedef struct 1082*da0073e9SAndroid Build Coastguard Worker { 1083*da0073e9SAndroid Build Coastguard Worker mz_zip_archive *pZip; 1084*da0073e9SAndroid Build Coastguard Worker mz_uint flags; 1085*da0073e9SAndroid Build Coastguard Worker 1086*da0073e9SAndroid Build Coastguard Worker int status; 1087*da0073e9SAndroid Build Coastguard Worker #ifndef MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS 1088*da0073e9SAndroid Build Coastguard Worker mz_uint file_crc32; 1089*da0073e9SAndroid Build Coastguard Worker #endif 1090*da0073e9SAndroid Build Coastguard Worker mz_uint64 read_buf_size, read_buf_ofs, read_buf_avail, comp_remaining, out_buf_ofs, cur_file_ofs; 1091*da0073e9SAndroid Build Coastguard Worker mz_zip_archive_file_stat file_stat; 1092*da0073e9SAndroid Build Coastguard Worker void *pRead_buf; 1093*da0073e9SAndroid Build Coastguard Worker void *pWrite_buf; 1094*da0073e9SAndroid Build Coastguard Worker 1095*da0073e9SAndroid Build Coastguard Worker size_t out_blk_remain; 1096*da0073e9SAndroid Build Coastguard Worker 1097*da0073e9SAndroid Build Coastguard Worker tinfl_decompressor inflator; 1098*da0073e9SAndroid Build Coastguard Worker 1099*da0073e9SAndroid Build Coastguard Worker } mz_zip_reader_extract_iter_state; 1100*da0073e9SAndroid Build Coastguard Worker 1101*da0073e9SAndroid Build Coastguard Worker /* -------- ZIP reading */ 1102*da0073e9SAndroid Build Coastguard Worker 1103*da0073e9SAndroid Build Coastguard Worker /* Inits a ZIP archive reader. */ 1104*da0073e9SAndroid Build Coastguard Worker /* These functions read and validate the archive's central directory. */ 1105*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint flags); 1106*da0073e9SAndroid Build Coastguard Worker 1107*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint flags); 1108*da0073e9SAndroid Build Coastguard Worker 1109*da0073e9SAndroid Build Coastguard Worker #ifndef MINIZ_NO_STDIO 1110*da0073e9SAndroid Build Coastguard Worker /* Read a archive from a disk file. */ 1111*da0073e9SAndroid Build Coastguard Worker /* file_start_ofs is the file offset where the archive actually begins, or 0. */ 1112*da0073e9SAndroid Build Coastguard Worker /* actual_archive_size is the true total size of the archive, which may be smaller than the file's actual size on disk. If zero the entire file is treated as the archive. */ 1113*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags); 1114*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags, mz_uint64 file_start_ofs, mz_uint64 archive_size); 1115*da0073e9SAndroid Build Coastguard Worker 1116*da0073e9SAndroid Build Coastguard Worker /* Read an archive from an already opened FILE, beginning at the current file position. */ 1117*da0073e9SAndroid Build Coastguard Worker /* The archive is assumed to be archive_size bytes long. If archive_size is < 0, then the entire rest of the file is assumed to contain the archive. */ 1118*da0073e9SAndroid Build Coastguard Worker /* The FILE will NOT be closed when mz_zip_reader_end() is called. */ 1119*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint64 archive_size, mz_uint flags); 1120*da0073e9SAndroid Build Coastguard Worker #endif 1121*da0073e9SAndroid Build Coastguard Worker 1122*da0073e9SAndroid Build Coastguard Worker /* Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used. */ 1123*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_end(mz_zip_archive *pZip); 1124*da0073e9SAndroid Build Coastguard Worker 1125*da0073e9SAndroid Build Coastguard Worker /* -------- ZIP reading or writing */ 1126*da0073e9SAndroid Build Coastguard Worker 1127*da0073e9SAndroid Build Coastguard Worker /* Clears a mz_zip_archive struct to all zeros. */ 1128*da0073e9SAndroid Build Coastguard Worker /* Important: This must be done before passing the struct to any mz_zip functions. */ 1129*da0073e9SAndroid Build Coastguard Worker void mz_zip_zero_struct(mz_zip_archive *pZip); 1130*da0073e9SAndroid Build Coastguard Worker 1131*da0073e9SAndroid Build Coastguard Worker mz_zip_mode mz_zip_get_mode(mz_zip_archive *pZip); 1132*da0073e9SAndroid Build Coastguard Worker mz_zip_type mz_zip_get_type(mz_zip_archive *pZip); 1133*da0073e9SAndroid Build Coastguard Worker 1134*da0073e9SAndroid Build Coastguard Worker /* Returns the total number of files in the archive. */ 1135*da0073e9SAndroid Build Coastguard Worker mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip); 1136*da0073e9SAndroid Build Coastguard Worker 1137*da0073e9SAndroid Build Coastguard Worker mz_uint64 mz_zip_get_archive_size(mz_zip_archive *pZip); 1138*da0073e9SAndroid Build Coastguard Worker mz_uint64 mz_zip_get_archive_file_start_offset(mz_zip_archive *pZip); 1139*da0073e9SAndroid Build Coastguard Worker MZ_FILE *mz_zip_get_cfile(mz_zip_archive *pZip); 1140*da0073e9SAndroid Build Coastguard Worker 1141*da0073e9SAndroid Build Coastguard Worker /* Reads n bytes of raw archive data, starting at file offset file_ofs, to pBuf. */ 1142*da0073e9SAndroid Build Coastguard Worker size_t mz_zip_read_archive_data(mz_zip_archive *pZip, mz_uint64 file_ofs, void *pBuf, size_t n); 1143*da0073e9SAndroid Build Coastguard Worker 1144*da0073e9SAndroid Build Coastguard Worker /* All mz_zip funcs set the m_last_error field in the mz_zip_archive struct. These functions retrieve/manipulate this field. */ 1145*da0073e9SAndroid Build Coastguard Worker /* Note that the m_last_error functionality is not thread safe. */ 1146*da0073e9SAndroid Build Coastguard Worker mz_zip_error mz_zip_set_last_error(mz_zip_archive *pZip, mz_zip_error err_num); 1147*da0073e9SAndroid Build Coastguard Worker mz_zip_error mz_zip_peek_last_error(mz_zip_archive *pZip); 1148*da0073e9SAndroid Build Coastguard Worker mz_zip_error mz_zip_clear_last_error(mz_zip_archive *pZip); 1149*da0073e9SAndroid Build Coastguard Worker mz_zip_error mz_zip_get_last_error(mz_zip_archive *pZip); 1150*da0073e9SAndroid Build Coastguard Worker const char *mz_zip_get_error_string(mz_zip_error mz_err); 1151*da0073e9SAndroid Build Coastguard Worker 1152*da0073e9SAndroid Build Coastguard Worker /* MZ_TRUE if the archive file entry is a directory entry. */ 1153*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index); 1154*da0073e9SAndroid Build Coastguard Worker 1155*da0073e9SAndroid Build Coastguard Worker /* MZ_TRUE if the file is encrypted/strong encrypted. */ 1156*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index); 1157*da0073e9SAndroid Build Coastguard Worker 1158*da0073e9SAndroid Build Coastguard Worker /* MZ_TRUE if the compression method is supported, and the file is not encrypted, and the file is not a compressed patch file. */ 1159*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_is_file_supported(mz_zip_archive *pZip, mz_uint file_index); 1160*da0073e9SAndroid Build Coastguard Worker 1161*da0073e9SAndroid Build Coastguard Worker /* Retrieves the filename of an archive file entry. */ 1162*da0073e9SAndroid Build Coastguard Worker /* Returns the number of bytes written to pFilename, or if filename_buf_size is 0 this function returns the number of bytes needed to fully store the filename. */ 1163*da0073e9SAndroid Build Coastguard Worker mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size); 1164*da0073e9SAndroid Build Coastguard Worker 1165*da0073e9SAndroid Build Coastguard Worker /* Attempts to locates a file in the archive's central directory. */ 1166*da0073e9SAndroid Build Coastguard Worker /* Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH */ 1167*da0073e9SAndroid Build Coastguard Worker /* Returns -1 if the file cannot be found. */ 1168*da0073e9SAndroid Build Coastguard Worker int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags); 1169*da0073e9SAndroid Build Coastguard Worker int mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags, mz_uint32 *file_index); 1170*da0073e9SAndroid Build Coastguard Worker 1171*da0073e9SAndroid Build Coastguard Worker /* Returns detailed information about an archive file entry. */ 1172*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat); 1173*da0073e9SAndroid Build Coastguard Worker 1174*da0073e9SAndroid Build Coastguard Worker /* MZ_TRUE if the file is in zip64 format. */ 1175*da0073e9SAndroid Build Coastguard Worker /* A file is considered zip64 if it contained a zip64 end of central directory marker, or if it contained any zip64 extended file information fields in the central directory. */ 1176*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_is_zip64(mz_zip_archive *pZip); 1177*da0073e9SAndroid Build Coastguard Worker 1178*da0073e9SAndroid Build Coastguard Worker /* Returns the total central directory size in bytes. */ 1179*da0073e9SAndroid Build Coastguard Worker /* The current max supported size is <= MZ_UINT32_MAX. */ 1180*da0073e9SAndroid Build Coastguard Worker size_t mz_zip_get_central_dir_size(mz_zip_archive *pZip); 1181*da0073e9SAndroid Build Coastguard Worker 1182*da0073e9SAndroid Build Coastguard Worker /* Extracts a archive file to a memory buffer using no memory allocation. */ 1183*da0073e9SAndroid Build Coastguard Worker /* There must be at least enough room on the stack to store the inflator's state (~34KB or so). */ 1184*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_extract_to_mem_no_alloc(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size); 1185*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_extract_file_to_mem_no_alloc(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size); 1186*da0073e9SAndroid Build Coastguard Worker 1187*da0073e9SAndroid Build Coastguard Worker /* Extracts a archive file to a memory buffer. */ 1188*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_extract_to_mem(mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size, mz_uint flags); 1189*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_extract_file_to_mem(mz_zip_archive *pZip, const char *pFilename, void *pBuf, size_t buf_size, mz_uint flags); 1190*da0073e9SAndroid Build Coastguard Worker 1191*da0073e9SAndroid Build Coastguard Worker /* Extracts a archive file to a dynamically allocated heap buffer. */ 1192*da0073e9SAndroid Build Coastguard Worker /* The memory will be allocated via the mz_zip_archive's alloc/realloc functions. */ 1193*da0073e9SAndroid Build Coastguard Worker /* Returns NULL and sets the last error on failure. */ 1194*da0073e9SAndroid Build Coastguard Worker void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags); 1195*da0073e9SAndroid Build Coastguard Worker void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags); 1196*da0073e9SAndroid Build Coastguard Worker 1197*da0073e9SAndroid Build Coastguard Worker /* Extracts a archive file using a callback function to output the file's data. */ 1198*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_extract_to_callback(mz_zip_archive *pZip, mz_uint file_index, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); 1199*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_extract_file_to_callback(mz_zip_archive *pZip, const char *pFilename, mz_file_write_func pCallback, void *pOpaque, mz_uint flags); 1200*da0073e9SAndroid Build Coastguard Worker 1201*da0073e9SAndroid Build Coastguard Worker /* Extract a file iteratively */ 1202*da0073e9SAndroid Build Coastguard Worker mz_zip_reader_extract_iter_state* mz_zip_reader_extract_iter_new(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags); 1203*da0073e9SAndroid Build Coastguard Worker mz_zip_reader_extract_iter_state* mz_zip_reader_extract_file_iter_new(mz_zip_archive *pZip, const char *pFilename, mz_uint flags); 1204*da0073e9SAndroid Build Coastguard Worker size_t mz_zip_reader_extract_iter_read(mz_zip_reader_extract_iter_state* pState, void* pvBuf, size_t buf_size); 1205*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_extract_iter_free(mz_zip_reader_extract_iter_state* pState); 1206*da0073e9SAndroid Build Coastguard Worker 1207*da0073e9SAndroid Build Coastguard Worker #ifndef MINIZ_NO_STDIO 1208*da0073e9SAndroid Build Coastguard Worker /* Extracts a archive file to a disk file and sets its last accessed and modified times. */ 1209*da0073e9SAndroid Build Coastguard Worker /* This function only extracts files, not archive directory records. */ 1210*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags); 1211*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags); 1212*da0073e9SAndroid Build Coastguard Worker 1213*da0073e9SAndroid Build Coastguard Worker /* Extracts a archive file starting at the current position in the destination FILE stream. */ 1214*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_extract_to_cfile(mz_zip_archive *pZip, mz_uint file_index, MZ_FILE *File, mz_uint flags); 1215*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_reader_extract_file_to_cfile(mz_zip_archive *pZip, const char *pArchive_filename, MZ_FILE *pFile, mz_uint flags); 1216*da0073e9SAndroid Build Coastguard Worker #endif 1217*da0073e9SAndroid Build Coastguard Worker 1218*da0073e9SAndroid Build Coastguard Worker #if 0 1219*da0073e9SAndroid Build Coastguard Worker /* TODO */ 1220*da0073e9SAndroid Build Coastguard Worker typedef void *mz_zip_streaming_extract_state_ptr; 1221*da0073e9SAndroid Build Coastguard Worker mz_zip_streaming_extract_state_ptr mz_zip_streaming_extract_begin(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags); 1222*da0073e9SAndroid Build Coastguard Worker uint64_t mz_zip_streaming_extract_get_size(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState); 1223*da0073e9SAndroid Build Coastguard Worker uint64_t mz_zip_streaming_extract_get_cur_ofs(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState); 1224*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_streaming_extract_seek(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, uint64_t new_ofs); 1225*da0073e9SAndroid Build Coastguard Worker size_t mz_zip_streaming_extract_read(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState, void *pBuf, size_t buf_size); 1226*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_streaming_extract_end(mz_zip_archive *pZip, mz_zip_streaming_extract_state_ptr pState); 1227*da0073e9SAndroid Build Coastguard Worker #endif 1228*da0073e9SAndroid Build Coastguard Worker 1229*da0073e9SAndroid Build Coastguard Worker /* This function compares the archive's local headers, the optional local zip64 extended information block, and the optional descriptor following the compressed data vs. the data in the central directory. */ 1230*da0073e9SAndroid Build Coastguard Worker /* It also validates that each file can be successfully uncompressed unless the MZ_ZIP_FLAG_VALIDATE_HEADERS_ONLY is specified. */ 1231*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_validate_file(mz_zip_archive *pZip, mz_uint file_index, mz_uint flags); 1232*da0073e9SAndroid Build Coastguard Worker 1233*da0073e9SAndroid Build Coastguard Worker /* Validates an entire archive by calling mz_zip_validate_file() on each file. */ 1234*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_validate_archive(mz_zip_archive *pZip, mz_uint flags); 1235*da0073e9SAndroid Build Coastguard Worker 1236*da0073e9SAndroid Build Coastguard Worker /* Misc utils/helpers, valid for ZIP reading or writing */ 1237*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_validate_mem_archive(const void *pMem, size_t size, mz_uint flags, mz_zip_error *pErr); 1238*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_validate_file_archive(const char *pFilename, mz_uint flags, mz_zip_error *pErr); 1239*da0073e9SAndroid Build Coastguard Worker 1240*da0073e9SAndroid Build Coastguard Worker /* Universal end function - calls either mz_zip_reader_end() or mz_zip_writer_end(). */ 1241*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_end(mz_zip_archive *pZip); 1242*da0073e9SAndroid Build Coastguard Worker 1243*da0073e9SAndroid Build Coastguard Worker /* -------- ZIP writing */ 1244*da0073e9SAndroid Build Coastguard Worker 1245*da0073e9SAndroid Build Coastguard Worker #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS 1246*da0073e9SAndroid Build Coastguard Worker 1247*da0073e9SAndroid Build Coastguard Worker /* Inits a ZIP archive writer. */ 1248*da0073e9SAndroid Build Coastguard Worker /*Set pZip->m_pWrite (and pZip->m_pIO_opaque) before calling mz_zip_writer_init or mz_zip_writer_init_v2*/ 1249*da0073e9SAndroid Build Coastguard Worker /*The output is streamable, i.e. file_ofs in mz_file_write_func always increases only by n*/ 1250*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size); 1251*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_init_v2(mz_zip_archive *pZip, mz_uint64 existing_size, mz_uint flags); 1252*da0073e9SAndroid Build Coastguard Worker 1253*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size); 1254*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_init_heap_v2(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size, mz_uint flags); 1255*da0073e9SAndroid Build Coastguard Worker 1256*da0073e9SAndroid Build Coastguard Worker #ifndef MINIZ_NO_STDIO 1257*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning); 1258*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_init_file_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning, mz_uint flags); 1259*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_init_cfile(mz_zip_archive *pZip, MZ_FILE *pFile, mz_uint flags); 1260*da0073e9SAndroid Build Coastguard Worker #endif 1261*da0073e9SAndroid Build Coastguard Worker 1262*da0073e9SAndroid Build Coastguard Worker /* Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive. */ 1263*da0073e9SAndroid Build Coastguard Worker /* For archives opened using mz_zip_reader_init_file, pFilename must be the archive's filename so it can be reopened for writing. If the file can't be reopened, mz_zip_reader_end() will be called. */ 1264*da0073e9SAndroid Build Coastguard Worker /* For archives opened using mz_zip_reader_init_mem, the memory block must be growable using the realloc callback (which defaults to realloc unless you've overridden it). */ 1265*da0073e9SAndroid Build Coastguard Worker /* Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL. */ 1266*da0073e9SAndroid Build Coastguard Worker /* Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before */ 1267*da0073e9SAndroid Build Coastguard Worker /* the archive is finalized the file's central directory will be hosed. */ 1268*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename); 1269*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_init_from_reader_v2(mz_zip_archive *pZip, const char *pFilename, mz_uint flags); 1270*da0073e9SAndroid Build Coastguard Worker 1271*da0073e9SAndroid Build Coastguard Worker /* Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive. */ 1272*da0073e9SAndroid Build Coastguard Worker /* To add a directory entry, call this method with an archive name ending in a forwardslash with an empty buffer. */ 1273*da0073e9SAndroid Build Coastguard Worker /* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */ 1274*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_add_mem(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, mz_uint level_and_flags); 1275*da0073e9SAndroid Build Coastguard Worker 1276*da0073e9SAndroid Build Coastguard Worker /* Like mz_zip_writer_add_mem(), except you can specify a file comment field, and optionally supply the function with already compressed data. */ 1277*da0073e9SAndroid Build Coastguard Worker /* uncomp_size/uncomp_crc32 are only used if the MZ_ZIP_FLAG_COMPRESSED_DATA flag is specified. */ 1278*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_add_mem_ex(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, 1279*da0073e9SAndroid Build Coastguard Worker mz_uint64 uncomp_size, mz_uint32 uncomp_crc32); 1280*da0073e9SAndroid Build Coastguard Worker 1281*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_add_mem_ex_v2(mz_zip_archive *pZip, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, 1282*da0073e9SAndroid Build Coastguard Worker mz_uint64 uncomp_size, mz_uint32 uncomp_crc32, MZ_TIME_T *last_modified, const char *user_extra_data_local, mz_uint user_extra_data_local_len, 1283*da0073e9SAndroid Build Coastguard Worker const char *user_extra_data_central, mz_uint user_extra_data_central_len); 1284*da0073e9SAndroid Build Coastguard Worker 1285*da0073e9SAndroid Build Coastguard Worker /* Adds the contents of a file to an archive. This function also records the disk file's modified time into the archive. */ 1286*da0073e9SAndroid Build Coastguard Worker /* File data is supplied via a read callback function. User mz_zip_writer_add_(c)file to add a file directly.*/ 1287*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_add_read_buf_callback(mz_zip_archive *pZip, const char *pArchive_name, mz_file_read_func read_callback, void* callback_opaque, mz_uint64 size_to_add, 1288*da0073e9SAndroid Build Coastguard Worker const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len, 1289*da0073e9SAndroid Build Coastguard Worker const char *user_extra_data_central, mz_uint user_extra_data_central_len); 1290*da0073e9SAndroid Build Coastguard Worker 1291*da0073e9SAndroid Build Coastguard Worker #ifndef MINIZ_NO_STDIO 1292*da0073e9SAndroid Build Coastguard Worker /* Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive. */ 1293*da0073e9SAndroid Build Coastguard Worker /* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */ 1294*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_add_file(mz_zip_archive *pZip, const char *pArchive_name, const char *pSrc_filename, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); 1295*da0073e9SAndroid Build Coastguard Worker 1296*da0073e9SAndroid Build Coastguard Worker /* Like mz_zip_writer_add_file(), except the file data is read from the specified FILE stream. */ 1297*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_add_cfile(mz_zip_archive *pZip, const char *pArchive_name, MZ_FILE *pSrc_file, mz_uint64 size_to_add, 1298*da0073e9SAndroid Build Coastguard Worker const MZ_TIME_T *pFile_time, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, const char *user_extra_data_local, mz_uint user_extra_data_local_len, 1299*da0073e9SAndroid Build Coastguard Worker const char *user_extra_data_central, mz_uint user_extra_data_central_len); 1300*da0073e9SAndroid Build Coastguard Worker #endif 1301*da0073e9SAndroid Build Coastguard Worker 1302*da0073e9SAndroid Build Coastguard Worker /* Adds a file to an archive by fully cloning the data from another archive. */ 1303*da0073e9SAndroid Build Coastguard Worker /* This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data (it may add or modify the zip64 local header extra data field), and the optional descriptor following the compressed data. */ 1304*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint src_file_index); 1305*da0073e9SAndroid Build Coastguard Worker 1306*da0073e9SAndroid Build Coastguard Worker /* Finalizes the archive by writing the central directory records followed by the end of central directory record. */ 1307*da0073e9SAndroid Build Coastguard Worker /* After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end(). */ 1308*da0073e9SAndroid Build Coastguard Worker /* An archive must be manually finalized by calling this function for it to be valid. */ 1309*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip); 1310*da0073e9SAndroid Build Coastguard Worker 1311*da0073e9SAndroid Build Coastguard Worker /* Finalizes a heap archive, returning a poiner to the heap block and its size. */ 1312*da0073e9SAndroid Build Coastguard Worker /* The heap block will be allocated using the mz_zip_archive's alloc/realloc callbacks. */ 1313*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **ppBuf, size_t *pSize); 1314*da0073e9SAndroid Build Coastguard Worker 1315*da0073e9SAndroid Build Coastguard Worker /* Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used. */ 1316*da0073e9SAndroid Build Coastguard Worker /* Note for the archive to be valid, it *must* have been finalized before ending (this function will not do it for you). */ 1317*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_writer_end(mz_zip_archive *pZip); 1318*da0073e9SAndroid Build Coastguard Worker 1319*da0073e9SAndroid Build Coastguard Worker /* -------- Misc. high-level helper functions: */ 1320*da0073e9SAndroid Build Coastguard Worker 1321*da0073e9SAndroid Build Coastguard Worker /* mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive. */ 1322*da0073e9SAndroid Build Coastguard Worker /* Note this is NOT a fully safe operation. If it crashes or dies in some way your archive can be left in a screwed up state (without a central directory). */ 1323*da0073e9SAndroid Build Coastguard Worker /* level_and_flags - compression level (0-10, see MZ_BEST_SPEED, MZ_BEST_COMPRESSION, etc.) logically OR'd with zero or more mz_zip_flags, or just set to MZ_DEFAULT_COMPRESSION. */ 1324*da0073e9SAndroid Build Coastguard Worker /* TODO: Perhaps add an option to leave the existing central dir in place in case the add dies? We could then truncate the file (so the old central dir would be at the end) if something goes wrong. */ 1325*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_add_mem_to_archive_file_in_place(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags); 1326*da0073e9SAndroid Build Coastguard Worker mz_bool mz_zip_add_mem_to_archive_file_in_place_v2(const char *pZip_filename, const char *pArchive_name, const void *pBuf, size_t buf_size, const void *pComment, mz_uint16 comment_size, mz_uint level_and_flags, mz_zip_error *pErr); 1327*da0073e9SAndroid Build Coastguard Worker 1328*da0073e9SAndroid Build Coastguard Worker /* Reads a single file from an archive into a heap block. */ 1329*da0073e9SAndroid Build Coastguard Worker /* If pComment is not NULL, only the file with the specified comment will be extracted. */ 1330*da0073e9SAndroid Build Coastguard Worker /* Returns NULL on failure. */ 1331*da0073e9SAndroid Build Coastguard Worker void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint flags); 1332*da0073e9SAndroid Build Coastguard Worker void *mz_zip_extract_archive_file_to_heap_v2(const char *pZip_filename, const char *pArchive_name, const char *pComment, size_t *pSize, mz_uint flags, mz_zip_error *pErr); 1333*da0073e9SAndroid Build Coastguard Worker 1334*da0073e9SAndroid Build Coastguard Worker #endif /* #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS */ 1335*da0073e9SAndroid Build Coastguard Worker 1336*da0073e9SAndroid Build Coastguard Worker #ifdef __cplusplus 1337*da0073e9SAndroid Build Coastguard Worker } 1338*da0073e9SAndroid Build Coastguard Worker #endif 1339*da0073e9SAndroid Build Coastguard Worker 1340*da0073e9SAndroid Build Coastguard Worker #endif /* MINIZ_NO_ARCHIVE_APIS */ 1341