#pragma once
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include "miniz_extra_defs.h"
#define MZ_DEFLATED 8
#define MZ_CRC32_INIT 0
#define LZ_CODE_BUF_SIZE (64 * 1024)
#define OUT_BUF_SIZE ((LZ_CODE_BUF_SIZE * 13) / 10)
#define LZ_DICT_FULL_SIZE (((LZ_DICT_SIZE + MAX_MATCH_LEN) - 1) + 1)
#define LZ_HASH_BITS 15
#define LZ_HASH_SHIFT ((LZ_HASH_BITS + 2) / 3)
#define LZ_HASH_SIZE (1 << LZ_HASH_BITS)
#define TDEFL_WRITE_ZLIB_HEADER 4096
#define TDEFL_COMPUTE_ADLER32 8192
#define TDEFL_GREEDY_PARSING_FLAG 16384
#define TDEFL_NONDETERMINISTIC_PARSING_FLAG 32768
#define TDEFL_RLE_MATCHES 65536
#define TDEFL_FILTER_MATCHES 131072
#define TDEFL_FORCE_ALL_STATIC_BLOCKS 262144
#define TDEFL_FORCE_ALL_RAW_BLOCKS 524288
#define TINFL_LZ_DICT_SIZE 32768
#define TINFL_FLAG_PARSE_ZLIB_HEADER 1
#define TINFL_FLAG_HAS_MORE_INPUT 2
#define TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF 4
#define TINFL_FLAG_COMPUTE_ADLER32 8
#define TINFL_FLAG_IGNORE_ADLER32 64
#define MZ_ADLER32_INIT 1
#define MZ_DEFAULT_WINDOW_BITS 15
typedef enum CAPICompressionLevel {
MZ_NO_COMPRESSION = 0,
MZ_BEST_SPEED = 1,
MZ_BEST_COMPRESSION = 9,
MZ_UBER_COMPRESSION = 10,
MZ_DEFAULT_LEVEL = 6,
MZ_DEFAULT_COMPRESSION = -1,
} CAPICompressionLevel;
typedef enum CAPICompressionStrategy {
MZ_DEFAULT_STRATEGY = 0,
MZ_FILTERED = 1,
MZ_HUFFMAN_ONLY = 2,
MZ_RLE = 3,
MZ_FIXED = 4,
} CAPICompressionStrategy;
typedef enum CAPIFlush {
MZ_NO_FLUSH = 0,
MZ_PARTIAL_FLUSH = 1,
MZ_SYNC_FLUSH = 2,
MZ_FULL_FLUSH = 3,
MZ_FINISH = 4,
MZ_BLOCK = 5,
} CAPIFlush;
typedef enum CAPIReturnStatus {
MZ_PARAM_ERROR = -10000,
MZ_VERSION_ERROR = -6,
MZ_BUF_ERROR = -5,
MZ_MEM_ERROR = -4,
MZ_DATA_ERROR = -3,
MZ_STREAM_ERROR = -2,
MZ_ERRNO = -1,
MZ_OK = 0,
MZ_STREAM_END = 1,
MZ_NEED_DICT = 2,
} CAPIReturnStatus;
typedef enum StateTypeEnum {
None = 0,
InflateType,
DeflateType,
} StateTypeEnum;
typedef enum tdefl_flush {
TDEFL_NO_FLUSH = 0,
TDEFL_SYNC_FLUSH = 2,
TDEFL_FULL_FLUSH = 3,
TDEFL_FINISH = 4,
} tdefl_flush;
typedef enum tdefl_status {
TDEFL_STATUS_BAD_PARAM = -2,
TDEFL_STATUS_PUT_BUF_FAILED = -1,
TDEFL_STATUS_OKAY = 0,
TDEFL_STATUS_DONE = 1,
} tdefl_status;
typedef enum tinfl_status {
TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS = -4,
TINFL_STATUS_BAD_PARAM = -3,
TINFL_STATUS_ADLER32_MISMATCH = -2,
TINFL_STATUS_FAILED = -1,
TINFL_STATUS_DONE = 0,
TINFL_STATUS_NEEDS_MORE_INPUT = 1,
TINFL_STATUS_HAS_MORE_OUTPUT = 2,
} tinfl_status;
typedef struct tdefl_compressor tdefl_compressor;
typedef struct DecompressorOxide DecompressorOxide;
typedef struct InternalState InternalState;
typedef void *(*mz_alloc_callback)(void*, size_t, size_t);
typedef void (*mz_free_callback)(void*, void*);
typedef struct mz_stream {
const uint8_t *next_in;
unsigned int avail_in;
unsigned long total_in;
uint8_t *next_out;
unsigned int avail_out;
unsigned long total_out;
const char *msg;
struct InternalState *state;
mz_alloc_callback zalloc;
mz_free_callback zfree;
void *opaque;
enum StateTypeEnum data_type;
unsigned long adler;
unsigned long reserved;
} mz_stream;
typedef int32_t (*tdefl_put_buf_func_ptr)(const void*, int, void*);
typedef struct tinfl_decompressor {
struct DecompressorOxide *inner;
} tinfl_decompressor;
typedef void *(*mz_alloc_func)(void*, size_t, size_t);
typedef void (*mz_free_func)(void*, void*);
typedef void *(*mz_realloc_func)(void*, void*, size_t, size_t);
#ifdef __cplusplus
extern "C" {
#endif
int mz_deflate(struct mz_stream *stream, int flush);
int mz_deflateEnd(struct mz_stream *stream);
int mz_deflateReset(struct mz_stream *stream);
int mz_inflate(struct mz_stream *stream, int flush);
int mz_inflateEnd(struct mz_stream *stream);
int mz_deflateInit(struct mz_stream *stream, int level);
int mz_deflateInit2(struct mz_stream *stream,
int level,
int method,
int window_bits,
int mem_level,
int strategy);
int mz_inflateInit2(struct mz_stream *stream, int window_bits);
int mz_compress(uint8_t *dest,
unsigned long *dest_len,
const uint8_t *source,
unsigned long source_len);
int mz_compress2(uint8_t *dest,
unsigned long *dest_len,
const uint8_t *source,
unsigned long source_len,
int level);
unsigned long mz_deflateBound(struct mz_stream *_stream, unsigned long source_len);
int mz_inflateInit(struct mz_stream *stream);
int mz_uncompress(uint8_t *dest,
unsigned long *dest_len,
const uint8_t *source,
unsigned long source_len);
unsigned long mz_compressBound(unsigned long source_len);
enum tdefl_status tdefl_compress(struct tdefl_compressor *d,
const void *in_buf,
uintptr_t *in_size,
void *out_buf,
uintptr_t *out_size,
enum tdefl_flush flush);
enum tdefl_status tdefl_compress_buffer(struct tdefl_compressor *d,
const void *in_buf,
uintptr_t in_size,
enum tdefl_flush flush);
struct tdefl_compressor *tdefl_allocate(void);
void tdefl_deallocate(struct tdefl_compressor *c);
enum tdefl_status tdefl_init(struct tdefl_compressor *d,
tdefl_put_buf_func_ptr put_buf_func,
void *put_buf_user,
int flags);
enum tdefl_status tdefl_get_prev_return_status(struct tdefl_compressor *d);
unsigned int tdefl_get_adler32(struct tdefl_compressor *d);
int tdefl_compress_mem_to_output(const void *buf,
uintptr_t buf_len,
tdefl_put_buf_func_ptr put_buf_func,
void *put_buf_user,
int flags);
void *tdefl_compress_mem_to_heap(const void *src_buf,
uintptr_t src_buf_len,
uintptr_t *out_len,
int flags);
uintptr_t tdefl_compress_mem_to_mem(void *out_buf,
uintptr_t out_buf_len,
const void *src_buf,
uintptr_t src_buf_len,
int flags);
unsigned int tdefl_create_comp_flags_from_zip_params(int level, int window_bits, int strategy);
int32_t tinfl_decompress(struct tinfl_decompressor *r,
const uint8_t *in_buf,
uintptr_t *in_buf_size,
uint8_t *out_buf_start,
uint8_t *out_buf_next,
uintptr_t *out_buf_size,
uint32_t flags);
size_t tinfl_decompress_mem_to_mem(void *p_out_buf,
size_t out_buf_len,
const void *p_src_buf,
size_t src_buf_len,
int flags);
void *tinfl_decompress_mem_to_heap(const void *p_src_buf,
size_t src_buf_len,
size_t *p_out_len,
int flags);
struct tinfl_decompressor *tinfl_decompressor_alloc(void);
void tinfl_decompressor_free(struct tinfl_decompressor *c);
void tinfl_init(struct tinfl_decompressor *c);
int tinfl_get_adler32(struct tinfl_decompressor *c);
void *miniz_def_alloc_func(void *_opaque, size_t items, size_t size);
void miniz_def_free_func(void *_opaque, void *address);
void *miniz_def_realloc_func(void *_opaque, void *address, size_t items, size_t size);
unsigned long mz_adler32(unsigned long adler, const uint8_t *ptr, uintptr_t buf_len);
unsigned long mz_crc32(unsigned long crc, const uint8_t *ptr, size_t buf_len);
#ifdef __cplusplus
} #endif