XenevaOS
Loading...
Searching...
No Matches
miniz_tinfl.h
Go to the documentation of this file.
1#pragma once
2#include "miniz_common.h"
3/* ------------------- Low-level Decompression API Definitions */
4
5#ifndef MINIZ_NO_INFLATE_APIS
6
7#ifdef __cplusplus
8extern "C" {
9#endif
10/* Decompression flags used by tinfl_decompress(). */
11/* 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. */
12/* 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. */
13/* 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). */
14/* TINFL_FLAG_COMPUTE_ADLER32: Force adler-32 checksum computation of the decompressed bytes. */
15enum
16{
21};
22
23/* High level decompression functions: */
24/* tinfl_decompress_mem_to_heap() decompresses a block in memory to a heap block allocated via malloc(). */
25/* On entry: */
26/* pSrc_buf, src_buf_len: Pointer and size of the Deflate or zlib source data to decompress. */
27/* On return: */
28/* Function returns a pointer to the decompressed data, or NULL on failure. */
29/* *pOut_len will be set to the decompressed data's size, which could be larger than src_buf_len on uncompressible data. */
30/* The caller must call mz_free() on the returned block when it's no longer needed. */
31MINIZ_EXPORT void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags);
32
33/* tinfl_decompress_mem_to_mem() decompresses a block in memory to another block in memory. */
34/* Returns TINFL_DECOMPRESS_MEM_TO_MEM_FAILED on failure, or the number of bytes written on success. */
35#define TINFL_DECOMPRESS_MEM_TO_MEM_FAILED ((size_t)(-1))
36MINIZ_EXPORT 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);
37
38/* 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. */
39/* Returns 1 on success or 0 on failure. */
40typedef int (*tinfl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser);
41MINIZ_EXPORT 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);
42
45
46#ifndef MINIZ_NO_MALLOC
47/* Allocate the tinfl_decompressor structure in C so that */
48/* non-C language bindings to tinfl_ API don't need to worry about */
49/* structure size and allocation mechanism. */
51MINIZ_EXPORT void tinfl_decompressor_free(tinfl_decompressor *pDecomp);
52#endif
53
54/* Max size of LZ dictionary. */
55#define TINFL_LZ_DICT_SIZE 32768
56
57/* Return status. */
58typedef enum {
59 /* This flags indicates the inflator needs 1 or more input bytes to make forward progress, but the caller is indicating that no more are available. The compressed data */
60 /* is probably corrupted. If you call the inflator again with more bytes it'll try to continue processing the input but this is a BAD sign (either the data is corrupted or you called it incorrectly). */
61 /* If you call it again with no input you'll just get TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS again. */
63
64 /* This flag indicates that one or more of the input parameters was obviously bogus. (You can try calling it again, but if you get this error the calling code is wrong.) */
66
67 /* This flags indicate the inflator is finished but the adler32 check of the uncompressed data didn't match. If you call it again it'll return TINFL_STATUS_DONE. */
69
70 /* This flags indicate the inflator has somehow failed (bad code, corrupted input, etc.). If you call it again without resetting via tinfl_init() it it'll just keep on returning the same status failure code. */
72
73 /* Any status code less than TINFL_STATUS_DONE must indicate a failure. */
74
75 /* This flag indicates the inflator has returned every byte of uncompressed data that it can, has consumed every byte that it needed, has successfully reached the end of the deflate stream, and */
76 /* if zlib headers and adler32 checking enabled that it has successfully checked the uncompressed data's adler32. If you call it again you'll just get TINFL_STATUS_DONE over and over again. */
78
79 /* This flag indicates the inflator MUST have more input data (even 1 byte) before it can make any more forward progress, or you need to clear the TINFL_FLAG_HAS_MORE_INPUT */
80 /* flag on the next call if you don't have any more source data. If the source data was somehow corrupted it's also possible (but unlikely) for the inflator to keep on demanding input to */
81 /* proceed, so be sure to properly set the TINFL_FLAG_HAS_MORE_INPUT flag. */
83
84 /* This flag indicates the inflator definitely has 1 or more bytes of uncompressed data available, but it cannot write this data into the output buffer. */
85 /* Note if the source compressed data was corrupted it's possible for the inflator to return a lot of uncompressed data to the caller. I've been assuming you know how much uncompressed data to expect */
86 /* (either exact or worst case) and will stop calling the inflator and fail after receiving too much. In pure streaming scenarios where you have no idea how many bytes to expect this may not be possible */
87 /* so I may need to add some code to address this. */
90
91/* Initializes the decompressor to its initial state. */
92#define tinfl_init(r) \
93 do \
94 { \
95 (r)->m_state = 0; \
96 } \
97 MZ_MACRO_END
98#define tinfl_get_adler32(r) (r)->m_check_adler32
99
100/* 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. */
101/* 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. */
102MINIZ_EXPORT 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);
103
104/* Internal/private bits follow. */
105enum
106{
114
115#if MINIZ_HAS_64BIT_REGISTERS
116#define TINFL_USE_64BIT_BITBUF 1
117#else
118#define TINFL_USE_64BIT_BITBUF 0
119#endif
120
121#if TINFL_USE_64BIT_BITBUF
123#define TINFL_BITBUF_SIZE (64)
124#else
126#define TINFL_BITBUF_SIZE (32)
127#endif
128
143
144#ifdef __cplusplus
145}
146#endif
147
148#endif /*#ifndef MINIZ_NO_INFLATE_APIS*/
uint8_t flags
Definition virtio.h:0
size_t len
Definition initial.c:23
signed short mz_int16
Definition miniz_common.h:11
unsigned char mz_uint8
Definition miniz_common.h:10
unsigned int mz_uint32
Definition miniz_common.h:13
uint64_t mz_uint64
Definition miniz_common.h:16
MINIZ_EXPORT 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)
Definition miniz_tinfl.c:720
MINIZ_EXPORT void tinfl_decompressor_free(tinfl_decompressor *pDecomp)
Definition miniz_tinfl.c:759
tinfl_status
Definition miniz_tinfl.h:58
@ TINFL_STATUS_ADLER32_MISMATCH
Definition miniz_tinfl.h:68
@ TINFL_STATUS_FAILED
Definition miniz_tinfl.h:71
@ TINFL_STATUS_NEEDS_MORE_INPUT
Definition miniz_tinfl.h:82
@ TINFL_STATUS_HAS_MORE_OUTPUT
Definition miniz_tinfl.h:88
@ TINFL_STATUS_BAD_PARAM
Definition miniz_tinfl.h:65
@ TINFL_STATUS_FAILED_CANNOT_MAKE_PROGRESS
Definition miniz_tinfl.h:62
@ TINFL_STATUS_DONE
Definition miniz_tinfl.h:77
MINIZ_EXPORT void * tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, size_t *pOut_len, int flags)
Definition miniz_tinfl.c:673
int(* tinfl_put_buf_func_ptr)(const void *pBuf, int len, void *pUser)
Definition miniz_tinfl.h:40
@ TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF
Definition miniz_tinfl.h:19
@ TINFL_FLAG_HAS_MORE_INPUT
Definition miniz_tinfl.h:18
@ TINFL_FLAG_COMPUTE_ADLER32
Definition miniz_tinfl.h:20
@ TINFL_FLAG_PARSE_ZLIB_HEADER
Definition miniz_tinfl.h:17
MINIZ_EXPORT 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)
Definition miniz_tinfl.c:711
@ TINFL_MAX_HUFF_SYMBOLS_2
Definition miniz_tinfl.h:110
@ TINFL_FAST_LOOKUP_SIZE
Definition miniz_tinfl.h:112
@ TINFL_MAX_HUFF_SYMBOLS_0
Definition miniz_tinfl.h:108
@ TINFL_MAX_HUFF_SYMBOLS_1
Definition miniz_tinfl.h:109
@ TINFL_MAX_HUFF_TABLES
Definition miniz_tinfl.h:107
@ TINFL_FAST_LOOKUP_BITS
Definition miniz_tinfl.h:111
MINIZ_EXPORT tinfl_decompressor * tinfl_decompressor_alloc(void)
Definition miniz_tinfl.c:751
MINIZ_EXPORT 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)
Definition miniz_tinfl.c:186
mz_uint32 tinfl_bit_buf_t
Definition miniz_tinfl.h:125
Definition miniz_tinfl.h:130
mz_uint8 m_code_size_0[TINFL_MAX_HUFF_SYMBOLS_0]
Definition miniz_tinfl.h:138
mz_uint32 m_type
Definition miniz_tinfl.h:131
mz_uint32 m_final
Definition miniz_tinfl.h:131
mz_uint32 m_zhdr0
Definition miniz_tinfl.h:131
tinfl_bit_buf_t m_bit_buf
Definition miniz_tinfl.h:132
mz_uint32 m_counter
Definition miniz_tinfl.h:131
size_t m_dist_from_out_buf_start
Definition miniz_tinfl.h:133
mz_uint32 m_check_adler32
Definition miniz_tinfl.h:131
mz_uint32 m_state
Definition miniz_tinfl.h:131
mz_int16 m_tree_0[TINFL_MAX_HUFF_SYMBOLS_0 *2]
Definition miniz_tinfl.h:135
mz_int16 m_tree_1[TINFL_MAX_HUFF_SYMBOLS_1 *2]
Definition miniz_tinfl.h:136
mz_uint8 m_raw_header[4]
Definition miniz_tinfl.h:141
mz_uint32 m_zhdr1
Definition miniz_tinfl.h:131
mz_uint32 m_num_bits
Definition miniz_tinfl.h:131
mz_int16 m_look_up[TINFL_MAX_HUFF_TABLES][TINFL_FAST_LOOKUP_SIZE]
Definition miniz_tinfl.h:134
mz_int16 m_tree_2[TINFL_MAX_HUFF_SYMBOLS_2 *2]
Definition miniz_tinfl.h:137
mz_uint32 m_z_adler32
Definition miniz_tinfl.h:131
mz_uint32 m_table_sizes[TINFL_MAX_HUFF_TABLES]
Definition miniz_tinfl.h:131
mz_uint32 m_dist
Definition miniz_tinfl.h:131
mz_uint8 m_code_size_2[TINFL_MAX_HUFF_SYMBOLS_2]
Definition miniz_tinfl.h:140
mz_uint8 m_len_codes[TINFL_MAX_HUFF_SYMBOLS_0+TINFL_MAX_HUFF_SYMBOLS_1+137]
Definition miniz_tinfl.h:141
mz_uint32 m_num_extra
Definition miniz_tinfl.h:131
mz_uint8 m_code_size_1[TINFL_MAX_HUFF_SYMBOLS_1]
Definition miniz_tinfl.h:139