Fossil SCM

removed double-application of miniz.h patch (doubled the content).

stephan 2014-08-20 14:54 miniz
Commit 935ccf9d6fee3e639899057f74d827c005f6b7d7
1 file changed -770
-770
--- src/miniz.h
+++ src/miniz.h
@@ -3071,775 +3071,5 @@
30713071
#ifdef __cplusplus
30723072
}
30733073
#endif
30743074
30753075
#endif // MINIZ_HEADER_INCLUDED
3076
-
3077
-#ifndef MINIZ_HEADER_INCLUDED
3078
-#define MINIZ_HEADER_INCLUDED
3079
-
3080
-#include <stdlib.h>
3081
-
3082
-// Defines to completely disable specific portions of miniz.c:
3083
-// If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl.
3084
-
3085
-// Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O.
3086
-#define MINIZ_NO_STDIO
3087
-
3088
-// If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or
3089
-// get/set file times, and the C run-time funcs that get/set times won't be called.
3090
-// The current downside is the times written to your archives will be from 1979.
3091
-#define MINIZ_NO_TIME
3092
-
3093
-// Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's.
3094
-#define MINIZ_NO_ARCHIVE_APIS
3095
-
3096
-// Define MINIZ_NO_ARCHIVE_APIS to disable all writing related ZIP archive API's.
3097
-#define MINIZ_NO_ARCHIVE_WRITING_APIS
3098
-
3099
-// Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's.
3100
-//#define MINIZ_NO_ZLIB_APIS
3101
-
3102
-// Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib.
3103
-//#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
3104
-
3105
-// Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
3106
-// Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
3107
-// callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
3108
-// functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work.
3109
-//#define MINIZ_NO_MALLOC
3110
-
3111
-#if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
3112
- // TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux
3113
- #define MINIZ_NO_TIME
3114
-#endif
3115
-
3116
-#if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
3117
- #include <time.h>
3118
-#endif
3119
-
3120
-#if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
3121
-// MINIZ_X86_OR_X64_CPU is only used to help set the below macros.
3122
-#define MINIZ_X86_OR_X64_CPU 1
3123
-#endif
3124
-
3125
-#if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
3126
-// Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian.
3127
-#define MINIZ_LITTLE_ENDIAN 1
3128
-#endif
3129
-
3130
-#if MINIZ_X86_OR_X64_CPU
3131
-// Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses.
3132
-#define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
3133
-#endif
3134
-
3135
-#if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
3136
-// 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).
3137
-#define MINIZ_HAS_64BIT_REGISTERS 1
3138
-#endif
3139
-
3140
-#ifdef __cplusplus
3141
-extern "C" {
3142
-#endif
3143
-
3144
-// ------------------- zlib-style API Definitions.
3145
-
3146
-// 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!
3147
-typedef unsigned long mz_ulong;
3148
-
3149
-// 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.
3150
-void mz_free(void *p);
3151
-
3152
-#define MZ_ADLER32_INIT (1)
3153
-// mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
3154
-mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
3155
-
3156
-#define MZ_CRC32_INIT (0)
3157
-// mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL.
3158
-mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
3159
-
3160
-// Compression strategies.
3161
-enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 };
3162
-
3163
-// Method
3164
-#define MZ_DEFLATED 8
3165
-
3166
-#ifndef MINIZ_NO_ZLIB_APIS
3167
-
3168
-// Heap allocation callbacks.
3169
-// Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long.
3170
-typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
3171
-typedef void (*mz_free_func)(void *opaque, void *address);
3172
-typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
3173
-
3174
-#define MZ_VERSION "9.1.15"
3175
-#define MZ_VERNUM 0x91F0
3176
-#define MZ_VER_MAJOR 9
3177
-#define MZ_VER_MINOR 1
3178
-#define MZ_VER_REVISION 15
3179
-#define MZ_VER_SUBREVISION 0
3180
-
3181
-// 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).
3182
-enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };
3183
-
3184
-// Return status codes. MZ_PARAM_ERROR is non-standard.
3185
-enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 };
3186
-
3187
-// 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.
3188
-enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 };
3189
-
3190
-// Window bits
3191
-#define MZ_DEFAULT_WINDOW_BITS 15
3192
-
3193
-struct mz_internal_state;
3194
-
3195
-// Compression/decompression stream struct.
3196
-typedef struct mz_stream_s
3197
-{
3198
- const unsigned char *next_in; // pointer to next byte to read
3199
- unsigned int avail_in; // number of bytes available at next_in
3200
- mz_ulong total_in; // total number of bytes consumed so far
3201
-
3202
- unsigned char *next_out; // pointer to next byte to write
3203
- unsigned int avail_out; // number of bytes that can be written to next_out
3204
- mz_ulong total_out; // total number of bytes produced so far
3205
-
3206
- char *msg; // error msg (unused)
3207
- struct mz_internal_state *state; // internal state, allocated by zalloc/zfree
3208
-
3209
- mz_alloc_func zalloc; // optional heap allocation function (defaults to malloc)
3210
- mz_free_func zfree; // optional heap free function (defaults to free)
3211
- void *opaque; // heap alloc function user pointer
3212
-
3213
- int data_type; // data_type (unused)
3214
- mz_ulong adler; // adler32 of the source or uncompressed data
3215
- mz_ulong reserved; // not used
3216
-} mz_stream;
3217
-
3218
-typedef mz_stream *mz_streamp;
3219
-
3220
-// Returns the version string of miniz.c.
3221
-const char *mz_version(void);
3222
-
3223
-// mz_deflateInit() initializes a compressor with default options:
3224
-// Parameters:
3225
-// pStream must point to an initialized mz_stream struct.
3226
-// level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION].
3227
-// level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio.
3228
-// (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.)
3229
-// Return values:
3230
-// MZ_OK on success.
3231
-// MZ_STREAM_ERROR if the stream is bogus.
3232
-// MZ_PARAM_ERROR if the input parameters are bogus.
3233
-// MZ_MEM_ERROR on out of memory.
3234
-int mz_deflateInit(mz_streamp pStream, int level);
3235
-
3236
-// mz_deflateInit2() is like mz_deflate(), except with more control:
3237
-// Additional parameters:
3238
-// method must be MZ_DEFLATED
3239
-// 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)
3240
-// mem_level must be between [1, 9] (it's checked but ignored by miniz.c)
3241
-int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
3242
-
3243
-// Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2().
3244
-int mz_deflateReset(mz_streamp pStream);
3245
-
3246
-// mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible.
3247
-// Parameters:
3248
-// 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.
3249
-// flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH.
3250
-// Return values:
3251
-// 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).
3252
-// 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.
3253
-// MZ_STREAM_ERROR if the stream is bogus.
3254
-// MZ_PARAM_ERROR if one of the parameters is invalid.
3255
-// 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.)
3256
-int mz_deflate(mz_streamp pStream, int flush);
3257
-
3258
-// mz_deflateEnd() deinitializes a compressor:
3259
-// Return values:
3260
-// MZ_OK on success.
3261
-// MZ_STREAM_ERROR if the stream is bogus.
3262
-int mz_deflateEnd(mz_streamp pStream);
3263
-
3264
-// 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.
3265
-mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
3266
-
3267
-// Single-call compression functions mz_compress() and mz_compress2():
3268
-// Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure.
3269
-int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
3270
-int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level);
3271
-
3272
-// mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress().
3273
-mz_ulong mz_compressBound(mz_ulong source_len);
3274
-
3275
-// Initializes a decompressor.
3276
-int mz_inflateInit(mz_streamp pStream);
3277
-
3278
-// 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:
3279
-// window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate).
3280
-int mz_inflateInit2(mz_streamp pStream, int window_bits);
3281
-
3282
-// 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.
3283
-// Parameters:
3284
-// 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.
3285
-// flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH.
3286
-// 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).
3287
-// 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.
3288
-// Return values:
3289
-// 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.
3290
-// 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.
3291
-// MZ_STREAM_ERROR if the stream is bogus.
3292
-// MZ_DATA_ERROR if the deflate stream is invalid.
3293
-// MZ_PARAM_ERROR if one of the parameters is invalid.
3294
-// 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
3295
-// with more input data, or with more room in the output buffer (except when using single call decompression, described above).
3296
-int mz_inflate(mz_streamp pStream, int flush);
3297
-
3298
-// Deinitializes a decompressor.
3299
-int mz_inflateEnd(mz_streamp pStream);
3300
-
3301
-// Single-call decompression.
3302
-// Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure.
3303
-int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
3304
-
3305
-// Returns a string description of the specified error code, or NULL if the error code is invalid.
3306
-const char *mz_error(int err);
3307
-
3308
-// 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.
3309
-// Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project.
3310
-#ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
3311
- typedef unsigned char Byte;
3312
- typedef unsigned int uInt;
3313
- typedef mz_ulong uLong;
3314
- typedef Byte Bytef;
3315
- typedef uInt uIntf;
3316
- typedef char charf;
3317
- typedef int intf;
3318
- typedef void *voidpf;
3319
- typedef uLong uLongf;
3320
- typedef void *voidp;
3321
- typedef void *const voidpc;
3322
- #define Z_NULL 0
3323
- #define Z_NO_FLUSH MZ_NO_FLUSH
3324
- #define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH
3325
- #define Z_SYNC_FLUSH MZ_SYNC_FLUSH
3326
- #define Z_FULL_FLUSH MZ_FULL_FLUSH
3327
- #define Z_FINISH MZ_FINISH
3328
- #define Z_BLOCK MZ_BLOCK
3329
- #define Z_OK MZ_OK
3330
- #define Z_STREAM_END MZ_STREAM_END
3331
- #define Z_NEED_DICT MZ_NEED_DICT
3332
- #define Z_ERRNO MZ_ERRNO
3333
- #define Z_STREAM_ERROR MZ_STREAM_ERROR
3334
- #define Z_DATA_ERROR MZ_DATA_ERROR
3335
- #define Z_MEM_ERROR MZ_MEM_ERROR
3336
- #define Z_BUF_ERROR MZ_BUF_ERROR
3337
- #define Z_VERSION_ERROR MZ_VERSION_ERROR
3338
- #define Z_PARAM_ERROR MZ_PARAM_ERROR
3339
- #define Z_NO_COMPRESSION MZ_NO_COMPRESSION
3340
- #define Z_BEST_SPEED MZ_BEST_SPEED
3341
- #define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION
3342
- #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION
3343
- #define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY
3344
- #define Z_FILTERED MZ_FILTERED
3345
- #define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY
3346
- #define Z_RLE MZ_RLE
3347
- #define Z_FIXED MZ_FIXED
3348
- #define Z_DEFLATED MZ_DEFLATED
3349
- #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
3350
- #define alloc_func mz_alloc_func
3351
- #define free_func mz_free_func
3352
- #define internal_state mz_internal_state
3353
- #define z_stream mz_stream
3354
- #define deflateInit mz_deflateInit
3355
- #define deflateInit2 mz_deflateInit2
3356
- #define deflateReset mz_deflateReset
3357
- #define deflate mz_deflate
3358
- #define deflateEnd mz_deflateEnd
3359
- #define deflateBound mz_deflateBound
3360
- #define compress mz_compress
3361
- #define compress2 mz_compress2
3362
- #define compressBound mz_compressBound
3363
- #define inflateInit mz_inflateInit
3364
- #define inflateInit2 mz_inflateInit2
3365
- #define inflate mz_inflate
3366
- #define inflateEnd mz_inflateEnd
3367
- #define uncompress mz_uncompress
3368
- #define crc32 mz_crc32
3369
- #define adler32 mz_adler32
3370
- #define MAX_WBITS 15
3371
- #define MAX_MEM_LEVEL 9
3372
- #define zError mz_error
3373
- #define ZLIB_VERSION MZ_VERSION
3374
- #define ZLIB_VERNUM MZ_VERNUM
3375
- #define ZLIB_VER_MAJOR MZ_VER_MAJOR
3376
- #define ZLIB_VER_MINOR MZ_VER_MINOR
3377
- #define ZLIB_VER_REVISION MZ_VER_REVISION
3378
- #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
3379
- #define zlibVersion mz_version
3380
- #define zlib_version mz_version()
3381
-#endif // #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
3382
-
3383
-#endif // MINIZ_NO_ZLIB_APIS
3384
-
3385
-// ------------------- Types and macros
3386
-
3387
-typedef unsigned char mz_uint8;
3388
-typedef signed short mz_int16;
3389
-typedef unsigned short mz_uint16;
3390
-typedef unsigned int mz_uint32;
3391
-typedef unsigned int mz_uint;
3392
-typedef long long mz_int64;
3393
-typedef unsigned long long mz_uint64;
3394
-typedef int mz_bool;
3395
-
3396
-#define MZ_FALSE (0)
3397
-#define MZ_TRUE (1)
3398
-
3399
-// An attempt to work around MSVC's spammy "warning C4127: conditional expression is constant" message.
3400
-#ifdef _MSC_VER
3401
- #define MZ_MACRO_END while (0, 0)
3402
-#else
3403
- #define MZ_MACRO_END while (0)
3404
-#endif
3405
-
3406
-// ------------------- ZIP archive reading/writing
3407
-
3408
-#ifndef MINIZ_NO_ARCHIVE_APIS
3409
-
3410
-enum
3411
-{
3412
- MZ_ZIP_MAX_IO_BUF_SIZE = 64*1024,
3413
- MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 260,
3414
- MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 256
3415
-};
3416
-
3417
-typedef struct
3418
-{
3419
- mz_uint32 m_file_index;
3420
- mz_uint32 m_central_dir_ofs;
3421
- mz_uint16 m_version_made_by;
3422
- mz_uint16 m_version_needed;
3423
- mz_uint16 m_bit_flag;
3424
- mz_uint16 m_method;
3425
-#ifndef MINIZ_NO_TIME
3426
- time_t m_time;
3427
-#endif
3428
- mz_uint32 m_crc32;
3429
- mz_uint64 m_comp_size;
3430
- mz_uint64 m_uncomp_size;
3431
- mz_uint16 m_internal_attr;
3432
- mz_uint32 m_external_attr;
3433
- mz_uint64 m_local_header_ofs;
3434
- mz_uint32 m_comment_size;
3435
- char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
3436
- char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
3437
-} mz_zip_archive_file_stat;
3438
-
3439
-typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n);
3440
-typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n);
3441
-
3442
-struct mz_zip_internal_state_tag;
3443
-typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
3444
-
3445
-typedef enum
3446
-{
3447
- MZ_ZIP_MODE_INVALID = 0,
3448
- MZ_ZIP_MODE_READING = 1,
3449
- MZ_ZIP_MODE_WRITING = 2,
3450
- MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
3451
-} mz_zip_mode;
3452
-
3453
-typedef struct mz_zip_archive_tag
3454
-{
3455
- mz_uint64 m_archive_size;
3456
- mz_uint64 m_central_directory_file_ofs;
3457
- mz_uint m_total_files;
3458
- mz_zip_mode m_zip_mode;
3459
-
3460
- mz_uint m_file_offset_alignment;
3461
-
3462
- mz_alloc_func m_pAlloc;
3463
- mz_free_func m_pFree;
3464
- mz_realloc_func m_pRealloc;
3465
- void *m_pAlloc_opaque;
3466
-
3467
- mz_file_read_func m_pRead;
3468
- mz_file_write_func m_pWrite;
3469
- void *m_pIO_opaque;
3470
-
3471
- mz_zip_internal_state *m_pState;
3472
-
3473
-} mz_zip_archive;
3474
-
3475
-typedef enum
3476
-{
3477
- MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
3478
- MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
3479
- MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
3480
- MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800
3481
-} mz_zip_flags;
3482
-
3483
-// ZIP archive reading
3484
-
3485
-// Inits a ZIP archive reader.
3486
-// These functions read and validate the archive's central directory.
3487
-mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint32 flags);
3488
-mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint32 flags);
3489
-
3490
-#ifndef MINIZ_NO_STDIO
3491
-mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
3492
-#endif
3493
-
3494
-// Returns the total number of files in the archive.
3495
-mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip);
3496
-
3497
-// Returns detailed information about an archive file entry.
3498
-mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
3499
-
3500
-// Determines if an archive file entry is a directory entry.
3501
-mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
3502
-mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
3503
-
3504
-// Retrieves the filename of an archive file entry.
3505
-// 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.
3506
-mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
3507
-
3508
-// Attempts to locates a file in the archive's central directory.
3509
-// Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH
3510
-// Returns -1 if the file cannot be found.
3511
-int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
3512
-
3513
-// Extracts a archive file to a memory buffer using no memory allocation.
3514
-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);
3515
-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);
3516
-
3517
-// Extracts a archive file to a memory buffer.
3518
-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);
3519
-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);
3520
-
3521
-// Extracts a archive file to a dynamically allocated heap buffer.
3522
-void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
3523
-void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
3524
-
3525
-// Extracts a archive file using a callback function to output the file's data.
3526
-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);
3527
-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);
3528
-
3529
-#ifndef MINIZ_NO_STDIO
3530
-// Extracts a archive file to a disk file and sets its last accessed and modified times.
3531
-// This function only extracts files, not archive directory records.
3532
-mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
3533
-mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
3534
-#endif
3535
-
3536
-// Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used.
3537
-mz_bool mz_zip_reader_end(mz_zip_archive *pZip);
3538
-
3539
-// ZIP archive writing
3540
-
3541
-#ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
3542
-
3543
-// Inits a ZIP archive writer.
3544
-mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size);
3545
-mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size);
3546
-
3547
-#ifndef MINIZ_NO_STDIO
3548
-mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
3549
-#endif
3550
-
3551
-// Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive.
3552
-// 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.
3553
-// 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).
3554
-// Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL.
3555
-// Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before
3556
-// the archive is finalized the file's central directory will be hosed.
3557
-mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename);
3558
-
3559
-// Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive.
3560
-// To add a directory entry, call this method with an archive name ending in a forwardslash with empty buffer.
3561
-// 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.
3562
-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);
3563
-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, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
3564
-
3565
-#ifndef MINIZ_NO_STDIO
3566
-// Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive.
3567
-// 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.
3568
-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);
3569
-#endif
3570
-
3571
-// Adds a file to an archive by fully cloning the data from another archive.
3572
-// This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data, and comment fields.
3573
-mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint file_index);
3574
-
3575
-// Finalizes the archive by writing the central directory records followed by the end of central directory record.
3576
-// After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end().
3577
-// An archive must be manually finalized by calling this function for it to be valid.
3578
-mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip);
3579
-mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **pBuf, size_t *pSize);
3580
-
3581
-// Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used.
3582
-// Note for the archive to be valid, it must have been finalized before ending.
3583
-mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
3584
-
3585
-// Misc. high-level helper functions:
3586
-
3587
-// mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive.
3588
-// 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.
3589
-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);
3590
-
3591
-// Reads a single file from an archive into a heap block.
3592
-// Returns NULL on failure.
3593
-void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint zip_flags);
3594
-
3595
-#endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
3596
-
3597
-#endif // #ifndef MINIZ_NO_ARCHIVE_APIS
3598
-
3599
-// ------------------- Low-level Decompression API Definitions
3600
-
3601
-// Decompression flags used by tinfl_decompress().
3602
-// 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.
3603
-// 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.
3604
-// 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).
3605
-// TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes.
3606
-enum
3607
-{
3608
- TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
3609
- TINFL_FLAG_HAS_MORE_INPUT = 2,
3610
- TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
3611
- TINFL_FLAG_COMPUTE_ADLER32 = 8
3612
-};
3613
-
3614
-// High level decompression functions:
3615
-// tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc().
3616
-// On entry:
3617
-// pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress.
3618
-// On return:
3619
-// Function returns a pointer to the decompressed data, or NULL on failure.
3620
-// *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data.
3621
-// The caller must call mz_free() on the returned block when it's no longer needed.
3622
-void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
3623
-
3624
-// tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory.
3625
-// Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success.
3626
-#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
3627
-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);
3628
-
3629
-// 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.
3630
-// Returns 1 on success or 0 on failure.
3631
-typedef int (*tinfl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
3632
-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);
3633
-
3634
-struct tinfl_decompressor_tag; typedef struct tinfl_decompressor_tag tinfl_decompressor;
3635
-
3636
-// Max size of LZ dictionary.
3637
-#define TINFL_LZ_DICT_SIZE 32768
3638
-
3639
-// Return status.
3640
-typedef enum
3641
-{
3642
- TINFL_STATUS_BAD_PARAM = -3,
3643
- TINFL_STATUS_ADLER32_MISMATCH = -2,
3644
- TINFL_STATUS_FAILED = -1,
3645
- TINFL_STATUS_DONE = 0,
3646
- TINFL_STATUS_NEEDS_MORE_INPUT = 1,
3647
- TINFL_STATUS_HAS_MORE_OUTPUT = 2
3648
-} tinfl_status;
3649
-
3650
-// Initializes the decompressor to its initial state.
3651
-#define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END
3652
-#define tinfl_get_adler32(r) (r)->m_check_adler32
3653
-
3654
-// 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.
3655
-// 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.
3656
-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);
3657
-
3658
-// Internal/private bits follow.
3659
-enum
3660
-{
3661
- TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19,
3662
- TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
3663
-};
3664
-
3665
-typedef struct
3666
-{
3667
- mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0];
3668
- mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
3669
-} tinfl_huff_table;
3670
-
3671
-#if MINIZ_HAS_64BIT_REGISTERS
3672
- #define TINFL_USE_64BIT_BITBUF 1
3673
-#endif
3674
-
3675
-#if TINFL_USE_64BIT_BITBUF
3676
- typedef mz_uint64 tinfl_bit_buf_t;
3677
- #define TINFL_BITBUF_SIZE (64)
3678
-#else
3679
- typedef mz_uint32 tinfl_bit_buf_t;
3680
- #define TINFL_BITBUF_SIZE (32)
3681
-#endif
3682
-
3683
-struct tinfl_decompressor_tag
3684
-{
3685
- 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];
3686
- tinfl_bit_buf_t m_bit_buf;
3687
- size_t m_dist_from_out_buf_start;
3688
- tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
3689
- mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
3690
-};
3691
-
3692
-// ------------------- Low-level Compression API Definitions
3693
-
3694
-// Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently).
3695
-#define TDEFL_LESS_MEMORY 0
3696
-
3697
-// tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search):
3698
-// 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).
3699
-enum
3700
-{
3701
- TDEFL_HUFFMAN_ONLY = 0, TDEFL_DEFAULT_MAX_PROBES = 128, TDEFL_MAX_PROBES_MASK = 0xFFF
3702
-};
3703
-
3704
-// 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.
3705
-// TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers).
3706
-// TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing.
3707
-// 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).
3708
-// TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1)
3709
-// TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled.
3710
-// TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables.
3711
-// TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks.
3712
-// The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK).
3713
-enum
3714
-{
3715
- TDEFL_WRITE_ZLIB_HEADER = 0x01000,
3716
- TDEFL_COMPUTE_ADLER32 = 0x02000,
3717
- TDEFL_GREEDY_PARSING_FLAG = 0x04000,
3718
- TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000,
3719
- TDEFL_RLE_MATCHES = 0x10000,
3720
- TDEFL_FILTER_MATCHES = 0x20000,
3721
- TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000,
3722
- TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000
3723
-};
3724
-
3725
-// High level compression functions:
3726
-// tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc().
3727
-// On entry:
3728
-// pSrc_buf, src_buf_len: Pointer and size of source block to compress.
3729
-// flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression.
3730
-// On return:
3731
-// Function returns a pointer to the compressed data, or NULL on failure.
3732
-// *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data.
3733
-// The caller must free() the returned block when it's no longer needed.
3734
-void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
3735
-
3736
-// tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory.
3737
-// Returns 0 on failure.
3738
-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);
3739
-
3740
-// Compresses an image to a compressed PNG file in memory.
3741
-// On entry:
3742
-// pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4.
3743
-// The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory.
3744
-// 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
3745
-// If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps).
3746
-// On return:
3747
-// Function returns a pointer to the compressed data, or NULL on failure.
3748
-// *pLen_out will be set to the size of the PNG image file.
3749
-// The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed.
3750
-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);
3751
-void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
3752
-
3753
-// Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
3754
-typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
3755
-
3756
-// tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally.
3757
-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);
3758
-
3759
-enum { TDEFL_MAX_HUFF_TABLES = 3, TDEFL_MAX_HUFF_SYMBOLS_0 = 288, TDEFL_MAX_HUFF_SYMBOLS_1 = 32, TDEFL_MAX_HUFF_SYMBOLS_2 = 19, TDEFL_LZ_DICT_SIZE = 32768, TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, TDEFL_MIN_MATCH_LEN = 3, TDEFL_MAX_MATCH_LEN = 258 };
3760
-
3761
-// TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes).
3762
-#if TDEFL_LESS_MEMORY
3763
-enum { TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 12, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
3764
-#else
3765
-enum { TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 15, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
3766
-#endif
3767
-
3768
-// 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.
3769
-typedef enum
3770
-{
3771
- TDEFL_STATUS_BAD_PARAM = -2,
3772
- TDEFL_STATUS_PUT_BUF_FAILED = -1,
3773
- TDEFL_STATUS_OKAY = 0,
3774
- TDEFL_STATUS_DONE = 1,
3775
-} tdefl_status;
3776
-
3777
-// Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums
3778
-typedef enum
3779
-{
3780
- TDEFL_NO_FLUSH = 0,
3781
- TDEFL_SYNC_FLUSH = 2,
3782
- TDEFL_FULL_FLUSH = 3,
3783
- TDEFL_FINISH = 4
3784
-} tdefl_flush;
3785
-
3786
-// tdefl's compression state structure.
3787
-typedef struct
3788
-{
3789
- tdefl_put_buf_func_ptr m_pPut_buf_func;
3790
- void *m_pPut_buf_user;
3791
- mz_uint m_flags, m_max_probes[2];
3792
- int m_greedy_parsing;
3793
- mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size;
3794
- mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end;
3795
- mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer;
3796
- 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;
3797
- tdefl_status m_prev_return_status;
3798
- const void *m_pIn_buf;
3799
- void *m_pOut_buf;
3800
- size_t *m_pIn_buf_size, *m_pOut_buf_size;
3801
- tdefl_flush m_flush;
3802
- const mz_uint8 *m_pSrc;
3803
- size_t m_src_buf_left, m_out_buf_ofs;
3804
- mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1];
3805
- mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
3806
- mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
3807
- mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
3808
- mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE];
3809
- mz_uint16 m_next[TDEFL_LZ_DICT_SIZE];
3810
- mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE];
3811
- mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
3812
-} tdefl_compressor;
3813
-
3814
-// Initializes the compressor.
3815
-// There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory.
3816
-// 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.
3817
-// If pBut_buf_func is NULL the user should always call the tdefl_compress() API.
3818
-// flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.)
3819
-tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
3820
-
3821
-// 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.
3822
-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);
3823
-
3824
-// tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr.
3825
-// tdefl_compress_buffer() always consumes the entire input buffer.
3826
-tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush);
3827
-
3828
-tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
3829
-mz_uint32 tdefl_get_adler32(tdefl_compressor *d);
3830
-
3831
-// Can't use tdefl_create_comp_flags_from_zip_params if MINIZ_NO_ZLIB_APIS isn't defined, because it uses some of its macros.
3832
-#ifndef MINIZ_NO_ZLIB_APIS
3833
-// Create tdefl_compress() flags given zlib-style compression parameters.
3834
-// level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files)
3835
-// window_bits may be -15 (raw deflate) or 15 (zlib)
3836
-// strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED
3837
-mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
3838
-#endif // #ifndef MINIZ_NO_ZLIB_APIS
3839
-
3840
-#ifdef __cplusplus
3841
-}
3842
-#endif
3843
-
3844
-#endif // MINIZ_HEADER_INCLUDED
3845
-
38463076
--- src/miniz.h
+++ src/miniz.h
@@ -3071,775 +3071,5 @@
3071 #ifdef __cplusplus
3072 }
3073 #endif
3074
3075 #endif // MINIZ_HEADER_INCLUDED
3076
3077 #ifndef MINIZ_HEADER_INCLUDED
3078 #define MINIZ_HEADER_INCLUDED
3079
3080 #include <stdlib.h>
3081
3082 // Defines to completely disable specific portions of miniz.c:
3083 // If all macros here are defined the only functionality remaining will be CRC-32, adler-32, tinfl, and tdefl.
3084
3085 // Define MINIZ_NO_STDIO to disable all usage and any functions which rely on stdio for file I/O.
3086 #define MINIZ_NO_STDIO
3087
3088 // If MINIZ_NO_TIME is specified then the ZIP archive functions will not be able to get the current time, or
3089 // get/set file times, and the C run-time funcs that get/set times won't be called.
3090 // The current downside is the times written to your archives will be from 1979.
3091 #define MINIZ_NO_TIME
3092
3093 // Define MINIZ_NO_ARCHIVE_APIS to disable all ZIP archive API's.
3094 #define MINIZ_NO_ARCHIVE_APIS
3095
3096 // Define MINIZ_NO_ARCHIVE_APIS to disable all writing related ZIP archive API's.
3097 #define MINIZ_NO_ARCHIVE_WRITING_APIS
3098
3099 // Define MINIZ_NO_ZLIB_APIS to remove all ZLIB-style compression/decompression API's.
3100 //#define MINIZ_NO_ZLIB_APIS
3101
3102 // Define MINIZ_NO_ZLIB_COMPATIBLE_NAME to disable zlib names, to prevent conflicts against stock zlib.
3103 //#define MINIZ_NO_ZLIB_COMPATIBLE_NAMES
3104
3105 // Define MINIZ_NO_MALLOC to disable all calls to malloc, free, and realloc.
3106 // Note if MINIZ_NO_MALLOC is defined then the user must always provide custom user alloc/free/realloc
3107 // callbacks to the zlib and archive API's, and a few stand-alone helper API's which don't provide custom user
3108 // functions (such as tdefl_compress_mem_to_heap() and tinfl_decompress_mem_to_heap()) won't work.
3109 //#define MINIZ_NO_MALLOC
3110
3111 #if defined(__TINYC__) && (defined(__linux) || defined(__linux__))
3112 // TODO: Work around "error: include file 'sys\utime.h' when compiling with tcc on Linux
3113 #define MINIZ_NO_TIME
3114 #endif
3115
3116 #if !defined(MINIZ_NO_TIME) && !defined(MINIZ_NO_ARCHIVE_APIS)
3117 #include <time.h>
3118 #endif
3119
3120 #if defined(_M_IX86) || defined(_M_X64) || defined(__i386__) || defined(__i386) || defined(__i486__) || defined(__i486) || defined(i386) || defined(__ia64__) || defined(__x86_64__)
3121 // MINIZ_X86_OR_X64_CPU is only used to help set the below macros.
3122 #define MINIZ_X86_OR_X64_CPU 1
3123 #endif
3124
3125 #if (__BYTE_ORDER__==__ORDER_LITTLE_ENDIAN__) || MINIZ_X86_OR_X64_CPU
3126 // Set MINIZ_LITTLE_ENDIAN to 1 if the processor is little endian.
3127 #define MINIZ_LITTLE_ENDIAN 1
3128 #endif
3129
3130 #if MINIZ_X86_OR_X64_CPU
3131 // Set MINIZ_USE_UNALIGNED_LOADS_AND_STORES to 1 on CPU's that permit efficient integer loads and stores from unaligned addresses.
3132 #define MINIZ_USE_UNALIGNED_LOADS_AND_STORES 1
3133 #endif
3134
3135 #if defined(_M_X64) || defined(_WIN64) || defined(__MINGW64__) || defined(_LP64) || defined(__LP64__) || defined(__ia64__) || defined(__x86_64__)
3136 // 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).
3137 #define MINIZ_HAS_64BIT_REGISTERS 1
3138 #endif
3139
3140 #ifdef __cplusplus
3141 extern "C" {
3142 #endif
3143
3144 // ------------------- zlib-style API Definitions.
3145
3146 // 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!
3147 typedef unsigned long mz_ulong;
3148
3149 // 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.
3150 void mz_free(void *p);
3151
3152 #define MZ_ADLER32_INIT (1)
3153 // mz_adler32() returns the initial adler-32 value to use when called with ptr==NULL.
3154 mz_ulong mz_adler32(mz_ulong adler, const unsigned char *ptr, size_t buf_len);
3155
3156 #define MZ_CRC32_INIT (0)
3157 // mz_crc32() returns the initial CRC-32 value to use when called with ptr==NULL.
3158 mz_ulong mz_crc32(mz_ulong crc, const unsigned char *ptr, size_t buf_len);
3159
3160 // Compression strategies.
3161 enum { MZ_DEFAULT_STRATEGY = 0, MZ_FILTERED = 1, MZ_HUFFMAN_ONLY = 2, MZ_RLE = 3, MZ_FIXED = 4 };
3162
3163 // Method
3164 #define MZ_DEFLATED 8
3165
3166 #ifndef MINIZ_NO_ZLIB_APIS
3167
3168 // Heap allocation callbacks.
3169 // Note that mz_alloc_func parameter types purpsosely differ from zlib's: items/size is size_t, not unsigned long.
3170 typedef void *(*mz_alloc_func)(void *opaque, size_t items, size_t size);
3171 typedef void (*mz_free_func)(void *opaque, void *address);
3172 typedef void *(*mz_realloc_func)(void *opaque, void *address, size_t items, size_t size);
3173
3174 #define MZ_VERSION "9.1.15"
3175 #define MZ_VERNUM 0x91F0
3176 #define MZ_VER_MAJOR 9
3177 #define MZ_VER_MINOR 1
3178 #define MZ_VER_REVISION 15
3179 #define MZ_VER_SUBREVISION 0
3180
3181 // 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).
3182 enum { MZ_NO_FLUSH = 0, MZ_PARTIAL_FLUSH = 1, MZ_SYNC_FLUSH = 2, MZ_FULL_FLUSH = 3, MZ_FINISH = 4, MZ_BLOCK = 5 };
3183
3184 // Return status codes. MZ_PARAM_ERROR is non-standard.
3185 enum { MZ_OK = 0, MZ_STREAM_END = 1, MZ_NEED_DICT = 2, MZ_ERRNO = -1, MZ_STREAM_ERROR = -2, MZ_DATA_ERROR = -3, MZ_MEM_ERROR = -4, MZ_BUF_ERROR = -5, MZ_VERSION_ERROR = -6, MZ_PARAM_ERROR = -10000 };
3186
3187 // 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.
3188 enum { MZ_NO_COMPRESSION = 0, MZ_BEST_SPEED = 1, MZ_BEST_COMPRESSION = 9, MZ_UBER_COMPRESSION = 10, MZ_DEFAULT_LEVEL = 6, MZ_DEFAULT_COMPRESSION = -1 };
3189
3190 // Window bits
3191 #define MZ_DEFAULT_WINDOW_BITS 15
3192
3193 struct mz_internal_state;
3194
3195 // Compression/decompression stream struct.
3196 typedef struct mz_stream_s
3197 {
3198 const unsigned char *next_in; // pointer to next byte to read
3199 unsigned int avail_in; // number of bytes available at next_in
3200 mz_ulong total_in; // total number of bytes consumed so far
3201
3202 unsigned char *next_out; // pointer to next byte to write
3203 unsigned int avail_out; // number of bytes that can be written to next_out
3204 mz_ulong total_out; // total number of bytes produced so far
3205
3206 char *msg; // error msg (unused)
3207 struct mz_internal_state *state; // internal state, allocated by zalloc/zfree
3208
3209 mz_alloc_func zalloc; // optional heap allocation function (defaults to malloc)
3210 mz_free_func zfree; // optional heap free function (defaults to free)
3211 void *opaque; // heap alloc function user pointer
3212
3213 int data_type; // data_type (unused)
3214 mz_ulong adler; // adler32 of the source or uncompressed data
3215 mz_ulong reserved; // not used
3216 } mz_stream;
3217
3218 typedef mz_stream *mz_streamp;
3219
3220 // Returns the version string of miniz.c.
3221 const char *mz_version(void);
3222
3223 // mz_deflateInit() initializes a compressor with default options:
3224 // Parameters:
3225 // pStream must point to an initialized mz_stream struct.
3226 // level must be between [MZ_NO_COMPRESSION, MZ_BEST_COMPRESSION].
3227 // level 1 enables a specially optimized compression function that's been optimized purely for performance, not ratio.
3228 // (This special func. is currently only enabled when MINIZ_USE_UNALIGNED_LOADS_AND_STORES and MINIZ_LITTLE_ENDIAN are defined.)
3229 // Return values:
3230 // MZ_OK on success.
3231 // MZ_STREAM_ERROR if the stream is bogus.
3232 // MZ_PARAM_ERROR if the input parameters are bogus.
3233 // MZ_MEM_ERROR on out of memory.
3234 int mz_deflateInit(mz_streamp pStream, int level);
3235
3236 // mz_deflateInit2() is like mz_deflate(), except with more control:
3237 // Additional parameters:
3238 // method must be MZ_DEFLATED
3239 // 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)
3240 // mem_level must be between [1, 9] (it's checked but ignored by miniz.c)
3241 int mz_deflateInit2(mz_streamp pStream, int level, int method, int window_bits, int mem_level, int strategy);
3242
3243 // Quickly resets a compressor without having to reallocate anything. Same as calling mz_deflateEnd() followed by mz_deflateInit()/mz_deflateInit2().
3244 int mz_deflateReset(mz_streamp pStream);
3245
3246 // mz_deflate() compresses the input to output, consuming as much of the input and producing as much output as possible.
3247 // Parameters:
3248 // 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.
3249 // flush may be MZ_NO_FLUSH, MZ_PARTIAL_FLUSH/MZ_SYNC_FLUSH, MZ_FULL_FLUSH, or MZ_FINISH.
3250 // Return values:
3251 // 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).
3252 // 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.
3253 // MZ_STREAM_ERROR if the stream is bogus.
3254 // MZ_PARAM_ERROR if one of the parameters is invalid.
3255 // 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.)
3256 int mz_deflate(mz_streamp pStream, int flush);
3257
3258 // mz_deflateEnd() deinitializes a compressor:
3259 // Return values:
3260 // MZ_OK on success.
3261 // MZ_STREAM_ERROR if the stream is bogus.
3262 int mz_deflateEnd(mz_streamp pStream);
3263
3264 // 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.
3265 mz_ulong mz_deflateBound(mz_streamp pStream, mz_ulong source_len);
3266
3267 // Single-call compression functions mz_compress() and mz_compress2():
3268 // Returns MZ_OK on success, or one of the error codes from mz_deflate() on failure.
3269 int mz_compress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
3270 int mz_compress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len, int level);
3271
3272 // mz_compressBound() returns a (very) conservative upper bound on the amount of data that could be generated by calling mz_compress().
3273 mz_ulong mz_compressBound(mz_ulong source_len);
3274
3275 // Initializes a decompressor.
3276 int mz_inflateInit(mz_streamp pStream);
3277
3278 // 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:
3279 // window_bits must be MZ_DEFAULT_WINDOW_BITS (to parse zlib header/footer) or -MZ_DEFAULT_WINDOW_BITS (raw deflate).
3280 int mz_inflateInit2(mz_streamp pStream, int window_bits);
3281
3282 // 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.
3283 // Parameters:
3284 // 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.
3285 // flush may be MZ_NO_FLUSH, MZ_SYNC_FLUSH, or MZ_FINISH.
3286 // 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).
3287 // 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.
3288 // Return values:
3289 // 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.
3290 // 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.
3291 // MZ_STREAM_ERROR if the stream is bogus.
3292 // MZ_DATA_ERROR if the deflate stream is invalid.
3293 // MZ_PARAM_ERROR if one of the parameters is invalid.
3294 // 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
3295 // with more input data, or with more room in the output buffer (except when using single call decompression, described above).
3296 int mz_inflate(mz_streamp pStream, int flush);
3297
3298 // Deinitializes a decompressor.
3299 int mz_inflateEnd(mz_streamp pStream);
3300
3301 // Single-call decompression.
3302 // Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure.
3303 int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
3304
3305 // Returns a string description of the specified error code, or NULL if the error code is invalid.
3306 const char *mz_error(int err);
3307
3308 // 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.
3309 // Define MINIZ_NO_ZLIB_COMPATIBLE_NAMES to disable zlib-compatibility if you use zlib in the same project.
3310 #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
3311 typedef unsigned char Byte;
3312 typedef unsigned int uInt;
3313 typedef mz_ulong uLong;
3314 typedef Byte Bytef;
3315 typedef uInt uIntf;
3316 typedef char charf;
3317 typedef int intf;
3318 typedef void *voidpf;
3319 typedef uLong uLongf;
3320 typedef void *voidp;
3321 typedef void *const voidpc;
3322 #define Z_NULL 0
3323 #define Z_NO_FLUSH MZ_NO_FLUSH
3324 #define Z_PARTIAL_FLUSH MZ_PARTIAL_FLUSH
3325 #define Z_SYNC_FLUSH MZ_SYNC_FLUSH
3326 #define Z_FULL_FLUSH MZ_FULL_FLUSH
3327 #define Z_FINISH MZ_FINISH
3328 #define Z_BLOCK MZ_BLOCK
3329 #define Z_OK MZ_OK
3330 #define Z_STREAM_END MZ_STREAM_END
3331 #define Z_NEED_DICT MZ_NEED_DICT
3332 #define Z_ERRNO MZ_ERRNO
3333 #define Z_STREAM_ERROR MZ_STREAM_ERROR
3334 #define Z_DATA_ERROR MZ_DATA_ERROR
3335 #define Z_MEM_ERROR MZ_MEM_ERROR
3336 #define Z_BUF_ERROR MZ_BUF_ERROR
3337 #define Z_VERSION_ERROR MZ_VERSION_ERROR
3338 #define Z_PARAM_ERROR MZ_PARAM_ERROR
3339 #define Z_NO_COMPRESSION MZ_NO_COMPRESSION
3340 #define Z_BEST_SPEED MZ_BEST_SPEED
3341 #define Z_BEST_COMPRESSION MZ_BEST_COMPRESSION
3342 #define Z_DEFAULT_COMPRESSION MZ_DEFAULT_COMPRESSION
3343 #define Z_DEFAULT_STRATEGY MZ_DEFAULT_STRATEGY
3344 #define Z_FILTERED MZ_FILTERED
3345 #define Z_HUFFMAN_ONLY MZ_HUFFMAN_ONLY
3346 #define Z_RLE MZ_RLE
3347 #define Z_FIXED MZ_FIXED
3348 #define Z_DEFLATED MZ_DEFLATED
3349 #define Z_DEFAULT_WINDOW_BITS MZ_DEFAULT_WINDOW_BITS
3350 #define alloc_func mz_alloc_func
3351 #define free_func mz_free_func
3352 #define internal_state mz_internal_state
3353 #define z_stream mz_stream
3354 #define deflateInit mz_deflateInit
3355 #define deflateInit2 mz_deflateInit2
3356 #define deflateReset mz_deflateReset
3357 #define deflate mz_deflate
3358 #define deflateEnd mz_deflateEnd
3359 #define deflateBound mz_deflateBound
3360 #define compress mz_compress
3361 #define compress2 mz_compress2
3362 #define compressBound mz_compressBound
3363 #define inflateInit mz_inflateInit
3364 #define inflateInit2 mz_inflateInit2
3365 #define inflate mz_inflate
3366 #define inflateEnd mz_inflateEnd
3367 #define uncompress mz_uncompress
3368 #define crc32 mz_crc32
3369 #define adler32 mz_adler32
3370 #define MAX_WBITS 15
3371 #define MAX_MEM_LEVEL 9
3372 #define zError mz_error
3373 #define ZLIB_VERSION MZ_VERSION
3374 #define ZLIB_VERNUM MZ_VERNUM
3375 #define ZLIB_VER_MAJOR MZ_VER_MAJOR
3376 #define ZLIB_VER_MINOR MZ_VER_MINOR
3377 #define ZLIB_VER_REVISION MZ_VER_REVISION
3378 #define ZLIB_VER_SUBREVISION MZ_VER_SUBREVISION
3379 #define zlibVersion mz_version
3380 #define zlib_version mz_version()
3381 #endif // #ifndef MINIZ_NO_ZLIB_COMPATIBLE_NAMES
3382
3383 #endif // MINIZ_NO_ZLIB_APIS
3384
3385 // ------------------- Types and macros
3386
3387 typedef unsigned char mz_uint8;
3388 typedef signed short mz_int16;
3389 typedef unsigned short mz_uint16;
3390 typedef unsigned int mz_uint32;
3391 typedef unsigned int mz_uint;
3392 typedef long long mz_int64;
3393 typedef unsigned long long mz_uint64;
3394 typedef int mz_bool;
3395
3396 #define MZ_FALSE (0)
3397 #define MZ_TRUE (1)
3398
3399 // An attempt to work around MSVC's spammy "warning C4127: conditional expression is constant" message.
3400 #ifdef _MSC_VER
3401 #define MZ_MACRO_END while (0, 0)
3402 #else
3403 #define MZ_MACRO_END while (0)
3404 #endif
3405
3406 // ------------------- ZIP archive reading/writing
3407
3408 #ifndef MINIZ_NO_ARCHIVE_APIS
3409
3410 enum
3411 {
3412 MZ_ZIP_MAX_IO_BUF_SIZE = 64*1024,
3413 MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE = 260,
3414 MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE = 256
3415 };
3416
3417 typedef struct
3418 {
3419 mz_uint32 m_file_index;
3420 mz_uint32 m_central_dir_ofs;
3421 mz_uint16 m_version_made_by;
3422 mz_uint16 m_version_needed;
3423 mz_uint16 m_bit_flag;
3424 mz_uint16 m_method;
3425 #ifndef MINIZ_NO_TIME
3426 time_t m_time;
3427 #endif
3428 mz_uint32 m_crc32;
3429 mz_uint64 m_comp_size;
3430 mz_uint64 m_uncomp_size;
3431 mz_uint16 m_internal_attr;
3432 mz_uint32 m_external_attr;
3433 mz_uint64 m_local_header_ofs;
3434 mz_uint32 m_comment_size;
3435 char m_filename[MZ_ZIP_MAX_ARCHIVE_FILENAME_SIZE];
3436 char m_comment[MZ_ZIP_MAX_ARCHIVE_FILE_COMMENT_SIZE];
3437 } mz_zip_archive_file_stat;
3438
3439 typedef size_t (*mz_file_read_func)(void *pOpaque, mz_uint64 file_ofs, void *pBuf, size_t n);
3440 typedef size_t (*mz_file_write_func)(void *pOpaque, mz_uint64 file_ofs, const void *pBuf, size_t n);
3441
3442 struct mz_zip_internal_state_tag;
3443 typedef struct mz_zip_internal_state_tag mz_zip_internal_state;
3444
3445 typedef enum
3446 {
3447 MZ_ZIP_MODE_INVALID = 0,
3448 MZ_ZIP_MODE_READING = 1,
3449 MZ_ZIP_MODE_WRITING = 2,
3450 MZ_ZIP_MODE_WRITING_HAS_BEEN_FINALIZED = 3
3451 } mz_zip_mode;
3452
3453 typedef struct mz_zip_archive_tag
3454 {
3455 mz_uint64 m_archive_size;
3456 mz_uint64 m_central_directory_file_ofs;
3457 mz_uint m_total_files;
3458 mz_zip_mode m_zip_mode;
3459
3460 mz_uint m_file_offset_alignment;
3461
3462 mz_alloc_func m_pAlloc;
3463 mz_free_func m_pFree;
3464 mz_realloc_func m_pRealloc;
3465 void *m_pAlloc_opaque;
3466
3467 mz_file_read_func m_pRead;
3468 mz_file_write_func m_pWrite;
3469 void *m_pIO_opaque;
3470
3471 mz_zip_internal_state *m_pState;
3472
3473 } mz_zip_archive;
3474
3475 typedef enum
3476 {
3477 MZ_ZIP_FLAG_CASE_SENSITIVE = 0x0100,
3478 MZ_ZIP_FLAG_IGNORE_PATH = 0x0200,
3479 MZ_ZIP_FLAG_COMPRESSED_DATA = 0x0400,
3480 MZ_ZIP_FLAG_DO_NOT_SORT_CENTRAL_DIRECTORY = 0x0800
3481 } mz_zip_flags;
3482
3483 // ZIP archive reading
3484
3485 // Inits a ZIP archive reader.
3486 // These functions read and validate the archive's central directory.
3487 mz_bool mz_zip_reader_init(mz_zip_archive *pZip, mz_uint64 size, mz_uint32 flags);
3488 mz_bool mz_zip_reader_init_mem(mz_zip_archive *pZip, const void *pMem, size_t size, mz_uint32 flags);
3489
3490 #ifndef MINIZ_NO_STDIO
3491 mz_bool mz_zip_reader_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint32 flags);
3492 #endif
3493
3494 // Returns the total number of files in the archive.
3495 mz_uint mz_zip_reader_get_num_files(mz_zip_archive *pZip);
3496
3497 // Returns detailed information about an archive file entry.
3498 mz_bool mz_zip_reader_file_stat(mz_zip_archive *pZip, mz_uint file_index, mz_zip_archive_file_stat *pStat);
3499
3500 // Determines if an archive file entry is a directory entry.
3501 mz_bool mz_zip_reader_is_file_a_directory(mz_zip_archive *pZip, mz_uint file_index);
3502 mz_bool mz_zip_reader_is_file_encrypted(mz_zip_archive *pZip, mz_uint file_index);
3503
3504 // Retrieves the filename of an archive file entry.
3505 // 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.
3506 mz_uint mz_zip_reader_get_filename(mz_zip_archive *pZip, mz_uint file_index, char *pFilename, mz_uint filename_buf_size);
3507
3508 // Attempts to locates a file in the archive's central directory.
3509 // Valid flags: MZ_ZIP_FLAG_CASE_SENSITIVE, MZ_ZIP_FLAG_IGNORE_PATH
3510 // Returns -1 if the file cannot be found.
3511 int mz_zip_reader_locate_file(mz_zip_archive *pZip, const char *pName, const char *pComment, mz_uint flags);
3512
3513 // Extracts a archive file to a memory buffer using no memory allocation.
3514 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);
3515 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);
3516
3517 // Extracts a archive file to a memory buffer.
3518 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);
3519 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);
3520
3521 // Extracts a archive file to a dynamically allocated heap buffer.
3522 void *mz_zip_reader_extract_to_heap(mz_zip_archive *pZip, mz_uint file_index, size_t *pSize, mz_uint flags);
3523 void *mz_zip_reader_extract_file_to_heap(mz_zip_archive *pZip, const char *pFilename, size_t *pSize, mz_uint flags);
3524
3525 // Extracts a archive file using a callback function to output the file's data.
3526 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);
3527 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);
3528
3529 #ifndef MINIZ_NO_STDIO
3530 // Extracts a archive file to a disk file and sets its last accessed and modified times.
3531 // This function only extracts files, not archive directory records.
3532 mz_bool mz_zip_reader_extract_to_file(mz_zip_archive *pZip, mz_uint file_index, const char *pDst_filename, mz_uint flags);
3533 mz_bool mz_zip_reader_extract_file_to_file(mz_zip_archive *pZip, const char *pArchive_filename, const char *pDst_filename, mz_uint flags);
3534 #endif
3535
3536 // Ends archive reading, freeing all allocations, and closing the input archive file if mz_zip_reader_init_file() was used.
3537 mz_bool mz_zip_reader_end(mz_zip_archive *pZip);
3538
3539 // ZIP archive writing
3540
3541 #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
3542
3543 // Inits a ZIP archive writer.
3544 mz_bool mz_zip_writer_init(mz_zip_archive *pZip, mz_uint64 existing_size);
3545 mz_bool mz_zip_writer_init_heap(mz_zip_archive *pZip, size_t size_to_reserve_at_beginning, size_t initial_allocation_size);
3546
3547 #ifndef MINIZ_NO_STDIO
3548 mz_bool mz_zip_writer_init_file(mz_zip_archive *pZip, const char *pFilename, mz_uint64 size_to_reserve_at_beginning);
3549 #endif
3550
3551 // Converts a ZIP archive reader object into a writer object, to allow efficient in-place file appends to occur on an existing archive.
3552 // 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.
3553 // 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).
3554 // Finally, for archives opened using mz_zip_reader_init, the mz_zip_archive's user provided m_pWrite function cannot be NULL.
3555 // Note: In-place archive modification is not recommended unless you know what you're doing, because if execution stops or something goes wrong before
3556 // the archive is finalized the file's central directory will be hosed.
3557 mz_bool mz_zip_writer_init_from_reader(mz_zip_archive *pZip, const char *pFilename);
3558
3559 // Adds the contents of a memory buffer to an archive. These functions record the current local time into the archive.
3560 // To add a directory entry, call this method with an archive name ending in a forwardslash with empty buffer.
3561 // 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.
3562 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);
3563 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, mz_uint64 uncomp_size, mz_uint32 uncomp_crc32);
3564
3565 #ifndef MINIZ_NO_STDIO
3566 // Adds the contents of a disk file to an archive. This function also records the disk file's modified time into the archive.
3567 // 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.
3568 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);
3569 #endif
3570
3571 // Adds a file to an archive by fully cloning the data from another archive.
3572 // This function fully clones the source file's compressed data (no recompression), along with its full filename, extra data, and comment fields.
3573 mz_bool mz_zip_writer_add_from_zip_reader(mz_zip_archive *pZip, mz_zip_archive *pSource_zip, mz_uint file_index);
3574
3575 // Finalizes the archive by writing the central directory records followed by the end of central directory record.
3576 // After an archive is finalized, the only valid call on the mz_zip_archive struct is mz_zip_writer_end().
3577 // An archive must be manually finalized by calling this function for it to be valid.
3578 mz_bool mz_zip_writer_finalize_archive(mz_zip_archive *pZip);
3579 mz_bool mz_zip_writer_finalize_heap_archive(mz_zip_archive *pZip, void **pBuf, size_t *pSize);
3580
3581 // Ends archive writing, freeing all allocations, and closing the output file if mz_zip_writer_init_file() was used.
3582 // Note for the archive to be valid, it must have been finalized before ending.
3583 mz_bool mz_zip_writer_end(mz_zip_archive *pZip);
3584
3585 // Misc. high-level helper functions:
3586
3587 // mz_zip_add_mem_to_archive_file_in_place() efficiently (but not atomically) appends a memory blob to a ZIP archive.
3588 // 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.
3589 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);
3590
3591 // Reads a single file from an archive into a heap block.
3592 // Returns NULL on failure.
3593 void *mz_zip_extract_archive_file_to_heap(const char *pZip_filename, const char *pArchive_name, size_t *pSize, mz_uint zip_flags);
3594
3595 #endif // #ifndef MINIZ_NO_ARCHIVE_WRITING_APIS
3596
3597 #endif // #ifndef MINIZ_NO_ARCHIVE_APIS
3598
3599 // ------------------- Low-level Decompression API Definitions
3600
3601 // Decompression flags used by tinfl_decompress().
3602 // 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.
3603 // 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.
3604 // 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).
3605 // TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes.
3606 enum
3607 {
3608 TINFL_FLAG_PARSE_ZLIB_HEADER = 1,
3609 TINFL_FLAG_HAS_MORE_INPUT = 2,
3610 TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF = 4,
3611 TINFL_FLAG_COMPUTE_ADLER32 = 8
3612 };
3613
3614 // High level decompression functions:
3615 // tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc().
3616 // On entry:
3617 // pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress.
3618 // On return:
3619 // Function returns a pointer to the decompressed data, or NULL on failure.
3620 // *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data.
3621 // The caller must call mz_free() on the returned block when it's no longer needed.
3622 void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
3623
3624 // tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory.
3625 // Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success.
3626 #define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
3627 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);
3628
3629 // 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.
3630 // Returns 1 on success or 0 on failure.
3631 typedef int (*tinfl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
3632 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);
3633
3634 struct tinfl_decompressor_tag; typedef struct tinfl_decompressor_tag tinfl_decompressor;
3635
3636 // Max size of LZ dictionary.
3637 #define TINFL_LZ_DICT_SIZE 32768
3638
3639 // Return status.
3640 typedef enum
3641 {
3642 TINFL_STATUS_BAD_PARAM = -3,
3643 TINFL_STATUS_ADLER32_MISMATCH = -2,
3644 TINFL_STATUS_FAILED = -1,
3645 TINFL_STATUS_DONE = 0,
3646 TINFL_STATUS_NEEDS_MORE_INPUT = 1,
3647 TINFL_STATUS_HAS_MORE_OUTPUT = 2
3648 } tinfl_status;
3649
3650 // Initializes the decompressor to its initial state.
3651 #define tinfl_init(r) do { (r)->m_state = 0; } MZ_MACRO_END
3652 #define tinfl_get_adler32(r) (r)->m_check_adler32
3653
3654 // 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.
3655 // 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.
3656 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);
3657
3658 // Internal/private bits follow.
3659 enum
3660 {
3661 TINFL_MAX_HUFF_TABLES = 3, TINFL_MAX_HUFF_SYMBOLS_0 = 288, TINFL_MAX_HUFF_SYMBOLS_1 = 32, TINFL_MAX_HUFF_SYMBOLS_2 = 19,
3662 TINFL_FAST_LOOKUP_BITS = 10, TINFL_FAST_LOOKUP_SIZE = 1 << TINFL_FAST_LOOKUP_BITS
3663 };
3664
3665 typedef struct
3666 {
3667 mz_uint8 m_code_size[TINFL_MAX_HUFF_SYMBOLS_0];
3668 mz_int16 m_look_up[TINFL_FAST_LOOKUP_SIZE], m_tree[TINFL_MAX_HUFF_SYMBOLS_0 * 2];
3669 } tinfl_huff_table;
3670
3671 #if MINIZ_HAS_64BIT_REGISTERS
3672 #define TINFL_USE_64BIT_BITBUF 1
3673 #endif
3674
3675 #if TINFL_USE_64BIT_BITBUF
3676 typedef mz_uint64 tinfl_bit_buf_t;
3677 #define TINFL_BITBUF_SIZE (64)
3678 #else
3679 typedef mz_uint32 tinfl_bit_buf_t;
3680 #define TINFL_BITBUF_SIZE (32)
3681 #endif
3682
3683 struct tinfl_decompressor_tag
3684 {
3685 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];
3686 tinfl_bit_buf_t m_bit_buf;
3687 size_t m_dist_from_out_buf_start;
3688 tinfl_huff_table m_tables[TINFL_MAX_HUFF_TABLES];
3689 mz_uint8 m_raw_header[4], m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0 + TINFL_MAX_HUFF_SYMBOLS_1 + 137];
3690 };
3691
3692 // ------------------- Low-level Compression API Definitions
3693
3694 // Set TDEFL_LESS_MEMORY to 1 to use less memory (compression will be slightly slower, and raw/dynamic blocks will be output more frequently).
3695 #define TDEFL_LESS_MEMORY 0
3696
3697 // tdefl_init() compression flags logically OR'd together (low 12 bits contain the max. number of probes per dictionary search):
3698 // 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).
3699 enum
3700 {
3701 TDEFL_HUFFMAN_ONLY = 0, TDEFL_DEFAULT_MAX_PROBES = 128, TDEFL_MAX_PROBES_MASK = 0xFFF
3702 };
3703
3704 // 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.
3705 // TDEFL_COMPUTE_ADLER32: Always compute the adler-32 of the input data (even when not writing zlib headers).
3706 // TDEFL_GREEDY_PARSING_FLAG: Set to use faster greedy parsing, instead of more efficient lazy parsing.
3707 // 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).
3708 // TDEFL_RLE_MATCHES: Only look for RLE matches (matches with a distance of 1)
3709 // TDEFL_FILTER_MATCHES: Discards matches <= 5 chars if enabled.
3710 // TDEFL_FORCE_ALL_STATIC_BLOCKS: Disable usage of optimized Huffman tables.
3711 // TDEFL_FORCE_ALL_RAW_BLOCKS: Only use raw (uncompressed) deflate blocks.
3712 // The low 12 bits are reserved to control the max # of hash probes per dictionary lookup (see TDEFL_MAX_PROBES_MASK).
3713 enum
3714 {
3715 TDEFL_WRITE_ZLIB_HEADER = 0x01000,
3716 TDEFL_COMPUTE_ADLER32 = 0x02000,
3717 TDEFL_GREEDY_PARSING_FLAG = 0x04000,
3718 TDEFL_NONDETERMINISTIC_PARSING_FLAG = 0x08000,
3719 TDEFL_RLE_MATCHES = 0x10000,
3720 TDEFL_FILTER_MATCHES = 0x20000,
3721 TDEFL_FORCE_ALL_STATIC_BLOCKS = 0x40000,
3722 TDEFL_FORCE_ALL_RAW_BLOCKS = 0x80000
3723 };
3724
3725 // High level compression functions:
3726 // tdefl_compress_mem_to_heap() compresses a block in memory to a heap block allocated via malloc().
3727 // On entry:
3728 // pSrc_buf, src_buf_len: Pointer and size of source block to compress.
3729 // flags: The max match finder probes (default is 128) logically OR'd against the above flags. Higher probes are slower but improve compression.
3730 // On return:
3731 // Function returns a pointer to the compressed data, or NULL on failure.
3732 // *pOut_len will be set to the compressed data's size, which could be larger than src_buf_len on uncompressible data.
3733 // The caller must free() the returned block when it's no longer needed.
3734 void *tdefl_compress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
3735
3736 // tdefl_compress_mem_to_mem() compresses a block in memory to another block in memory.
3737 // Returns 0 on failure.
3738 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);
3739
3740 // Compresses an image to a compressed PNG file in memory.
3741 // On entry:
3742 // pImage, w, h, and num_chans describe the image to compress. num_chans may be 1, 2, 3, or 4.
3743 // The image pitch in bytes per scanline will be w*num_chans. The leftmost pixel on the top scanline is stored first in memory.
3744 // 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
3745 // If flip is true, the image will be flipped on the Y axis (useful for OpenGL apps).
3746 // On return:
3747 // Function returns a pointer to the compressed data, or NULL on failure.
3748 // *pLen_out will be set to the size of the PNG image file.
3749 // The caller must mz_free() the returned heap block (which will typically be larger than *pLen_out) when it's no longer needed.
3750 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);
3751 void *tdefl_write_image_to_png_file_in_memory(const void *pImage, int w, int h, int num_chans, size_t *pLen_out);
3752
3753 // Output stream interface. The compressor uses this interface to write compressed data. It'll typically be called TDEFL_OUT_BUF_SIZE at a time.
3754 typedef mz_bool (*tdefl_put_buf_func_ptr)(const void* pBuf, int len, void *pUser);
3755
3756 // tdefl_compress_mem_to_output() compresses a block to an output stream. The above helpers use this function internally.
3757 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);
3758
3759 enum { TDEFL_MAX_HUFF_TABLES = 3, TDEFL_MAX_HUFF_SYMBOLS_0 = 288, TDEFL_MAX_HUFF_SYMBOLS_1 = 32, TDEFL_MAX_HUFF_SYMBOLS_2 = 19, TDEFL_LZ_DICT_SIZE = 32768, TDEFL_LZ_DICT_SIZE_MASK = TDEFL_LZ_DICT_SIZE - 1, TDEFL_MIN_MATCH_LEN = 3, TDEFL_MAX_MATCH_LEN = 258 };
3760
3761 // TDEFL_OUT_BUF_SIZE MUST be large enough to hold a single entire compressed output block (using static/fixed Huffman codes).
3762 #if TDEFL_LESS_MEMORY
3763 enum { TDEFL_LZ_CODE_BUF_SIZE = 24 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 12, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
3764 #else
3765 enum { TDEFL_LZ_CODE_BUF_SIZE = 64 * 1024, TDEFL_OUT_BUF_SIZE = (TDEFL_LZ_CODE_BUF_SIZE * 13 ) / 10, TDEFL_MAX_HUFF_SYMBOLS = 288, TDEFL_LZ_HASH_BITS = 15, TDEFL_LEVEL1_HASH_SIZE_MASK = 4095, TDEFL_LZ_HASH_SHIFT = (TDEFL_LZ_HASH_BITS + 2) / 3, TDEFL_LZ_HASH_SIZE = 1 << TDEFL_LZ_HASH_BITS };
3766 #endif
3767
3768 // 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.
3769 typedef enum
3770 {
3771 TDEFL_STATUS_BAD_PARAM = -2,
3772 TDEFL_STATUS_PUT_BUF_FAILED = -1,
3773 TDEFL_STATUS_OKAY = 0,
3774 TDEFL_STATUS_DONE = 1,
3775 } tdefl_status;
3776
3777 // Must map to MZ_NO_FLUSH, MZ_SYNC_FLUSH, etc. enums
3778 typedef enum
3779 {
3780 TDEFL_NO_FLUSH = 0,
3781 TDEFL_SYNC_FLUSH = 2,
3782 TDEFL_FULL_FLUSH = 3,
3783 TDEFL_FINISH = 4
3784 } tdefl_flush;
3785
3786 // tdefl's compression state structure.
3787 typedef struct
3788 {
3789 tdefl_put_buf_func_ptr m_pPut_buf_func;
3790 void *m_pPut_buf_user;
3791 mz_uint m_flags, m_max_probes[2];
3792 int m_greedy_parsing;
3793 mz_uint m_adler32, m_lookahead_pos, m_lookahead_size, m_dict_size;
3794 mz_uint8 *m_pLZ_code_buf, *m_pLZ_flags, *m_pOutput_buf, *m_pOutput_buf_end;
3795 mz_uint m_num_flags_left, m_total_lz_bytes, m_lz_code_buf_dict_pos, m_bits_in, m_bit_buffer;
3796 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;
3797 tdefl_status m_prev_return_status;
3798 const void *m_pIn_buf;
3799 void *m_pOut_buf;
3800 size_t *m_pIn_buf_size, *m_pOut_buf_size;
3801 tdefl_flush m_flush;
3802 const mz_uint8 *m_pSrc;
3803 size_t m_src_buf_left, m_out_buf_ofs;
3804 mz_uint8 m_dict[TDEFL_LZ_DICT_SIZE + TDEFL_MAX_MATCH_LEN - 1];
3805 mz_uint16 m_huff_count[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
3806 mz_uint16 m_huff_codes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
3807 mz_uint8 m_huff_code_sizes[TDEFL_MAX_HUFF_TABLES][TDEFL_MAX_HUFF_SYMBOLS];
3808 mz_uint8 m_lz_code_buf[TDEFL_LZ_CODE_BUF_SIZE];
3809 mz_uint16 m_next[TDEFL_LZ_DICT_SIZE];
3810 mz_uint16 m_hash[TDEFL_LZ_HASH_SIZE];
3811 mz_uint8 m_output_buf[TDEFL_OUT_BUF_SIZE];
3812 } tdefl_compressor;
3813
3814 // Initializes the compressor.
3815 // There is no corresponding deinit() function because the tdefl API's do not dynamically allocate memory.
3816 // 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.
3817 // If pBut_buf_func is NULL the user should always call the tdefl_compress() API.
3818 // flags: See the above enums (TDEFL_HUFFMAN_ONLY, TDEFL_WRITE_ZLIB_HEADER, etc.)
3819 tdefl_status tdefl_init(tdefl_compressor *d, tdefl_put_buf_func_ptr pPut_buf_func, void *pPut_buf_user, int flags);
3820
3821 // 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.
3822 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);
3823
3824 // tdefl_compress_buffer() is only usable when the tdefl_init() is called with a non-NULL tdefl_put_buf_func_ptr.
3825 // tdefl_compress_buffer() always consumes the entire input buffer.
3826 tdefl_status tdefl_compress_buffer(tdefl_compressor *d, const void *pIn_buf, size_t in_buf_size, tdefl_flush flush);
3827
3828 tdefl_status tdefl_get_prev_return_status(tdefl_compressor *d);
3829 mz_uint32 tdefl_get_adler32(tdefl_compressor *d);
3830
3831 // Can't use tdefl_create_comp_flags_from_zip_params if MINIZ_NO_ZLIB_APIS isn't defined, because it uses some of its macros.
3832 #ifndef MINIZ_NO_ZLIB_APIS
3833 // Create tdefl_compress() flags given zlib-style compression parameters.
3834 // level may range from [0,10] (where 10 is absolute max compression, but may be much slower on some files)
3835 // window_bits may be -15 (raw deflate) or 15 (zlib)
3836 // strategy may be either MZ_DEFAULT_STRATEGY, MZ_FILTERED, MZ_HUFFMAN_ONLY, MZ_RLE, or MZ_FIXED
3837 mz_uint tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
3838 #endif // #ifndef MINIZ_NO_ZLIB_APIS
3839
3840 #ifdef __cplusplus
3841 }
3842 #endif
3843
3844 #endif // MINIZ_HEADER_INCLUDED
3845
3846
--- src/miniz.h
+++ src/miniz.h
@@ -3071,775 +3071,5 @@
3071 #ifdef __cplusplus
3072 }
3073 #endif
3074
3075 #endif // MINIZ_HEADER_INCLUDED
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3076

Keyboard Shortcuts

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