diff options
Diffstat (limited to 'C/Lzma2Dec.h')
-rw-r--r-- | C/Lzma2Dec.h | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/C/Lzma2Dec.h b/C/Lzma2Dec.h new file mode 100644 index 0000000..b8ddeac --- /dev/null +++ b/C/Lzma2Dec.h | |||
@@ -0,0 +1,120 @@ | |||
1 | /* Lzma2Dec.h -- LZMA2 Decoder | ||
2 | 2018-02-19 : Igor Pavlov : Public domain */ | ||
3 | |||
4 | #ifndef __LZMA2_DEC_H | ||
5 | #define __LZMA2_DEC_H | ||
6 | |||
7 | #include "LzmaDec.h" | ||
8 | |||
9 | EXTERN_C_BEGIN | ||
10 | |||
11 | /* ---------- State Interface ---------- */ | ||
12 | |||
13 | typedef struct | ||
14 | { | ||
15 | unsigned state; | ||
16 | Byte control; | ||
17 | Byte needInitLevel; | ||
18 | Byte isExtraMode; | ||
19 | Byte _pad_; | ||
20 | UInt32 packSize; | ||
21 | UInt32 unpackSize; | ||
22 | CLzmaDec decoder; | ||
23 | } CLzma2Dec; | ||
24 | |||
25 | #define Lzma2Dec_Construct(p) LzmaDec_Construct(&(p)->decoder) | ||
26 | #define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc) | ||
27 | #define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc) | ||
28 | |||
29 | SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAllocPtr alloc); | ||
30 | SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAllocPtr alloc); | ||
31 | void Lzma2Dec_Init(CLzma2Dec *p); | ||
32 | |||
33 | /* | ||
34 | finishMode: | ||
35 | It has meaning only if the decoding reaches output limit (*destLen or dicLimit). | ||
36 | LZMA_FINISH_ANY - use smallest number of input bytes | ||
37 | LZMA_FINISH_END - read EndOfStream marker after decoding | ||
38 | |||
39 | Returns: | ||
40 | SZ_OK | ||
41 | status: | ||
42 | LZMA_STATUS_FINISHED_WITH_MARK | ||
43 | LZMA_STATUS_NOT_FINISHED | ||
44 | LZMA_STATUS_NEEDS_MORE_INPUT | ||
45 | SZ_ERROR_DATA - Data error | ||
46 | */ | ||
47 | |||
48 | SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit, | ||
49 | const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); | ||
50 | |||
51 | SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen, | ||
52 | const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status); | ||
53 | |||
54 | |||
55 | /* ---------- LZMA2 block and chunk parsing ---------- */ | ||
56 | |||
57 | /* | ||
58 | Lzma2Dec_Parse() parses compressed data stream up to next independent block or next chunk data. | ||
59 | It can return LZMA_STATUS_* code or LZMA2_PARSE_STATUS_* code: | ||
60 | - LZMA2_PARSE_STATUS_NEW_BLOCK - there is new block, and 1 additional byte (control byte of next block header) was read from input. | ||
61 | - LZMA2_PARSE_STATUS_NEW_CHUNK - there is new chunk, and only lzma2 header of new chunk was read. | ||
62 | CLzma2Dec::unpackSize contains unpack size of that chunk | ||
63 | */ | ||
64 | |||
65 | typedef enum | ||
66 | { | ||
67 | /* | ||
68 | LZMA_STATUS_NOT_SPECIFIED // data error | ||
69 | LZMA_STATUS_FINISHED_WITH_MARK | ||
70 | LZMA_STATUS_NOT_FINISHED // | ||
71 | LZMA_STATUS_NEEDS_MORE_INPUT | ||
72 | LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK // unused | ||
73 | */ | ||
74 | LZMA2_PARSE_STATUS_NEW_BLOCK = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK + 1, | ||
75 | LZMA2_PARSE_STATUS_NEW_CHUNK | ||
76 | } ELzma2ParseStatus; | ||
77 | |||
78 | ELzma2ParseStatus Lzma2Dec_Parse(CLzma2Dec *p, | ||
79 | SizeT outSize, // output size | ||
80 | const Byte *src, SizeT *srcLen, | ||
81 | int checkFinishBlock // set (checkFinishBlock = 1), if it must read full input data, if decoder.dicPos reaches blockMax position. | ||
82 | ); | ||
83 | |||
84 | /* | ||
85 | LZMA2 parser doesn't decode LZMA chunks, so we must read | ||
86 | full input LZMA chunk to decode some part of LZMA chunk. | ||
87 | |||
88 | Lzma2Dec_GetUnpackExtra() returns the value that shows | ||
89 | max possible number of output bytes that can be output by decoder | ||
90 | at current input positon. | ||
91 | */ | ||
92 | |||
93 | #define Lzma2Dec_GetUnpackExtra(p) ((p)->isExtraMode ? (p)->unpackSize : 0); | ||
94 | |||
95 | |||
96 | /* ---------- One Call Interface ---------- */ | ||
97 | |||
98 | /* | ||
99 | finishMode: | ||
100 | It has meaning only if the decoding reaches output limit (*destLen). | ||
101 | LZMA_FINISH_ANY - use smallest number of input bytes | ||
102 | LZMA_FINISH_END - read EndOfStream marker after decoding | ||
103 | |||
104 | Returns: | ||
105 | SZ_OK | ||
106 | status: | ||
107 | LZMA_STATUS_FINISHED_WITH_MARK | ||
108 | LZMA_STATUS_NOT_FINISHED | ||
109 | SZ_ERROR_DATA - Data error | ||
110 | SZ_ERROR_MEM - Memory allocation error | ||
111 | SZ_ERROR_UNSUPPORTED - Unsupported properties | ||
112 | SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src). | ||
113 | */ | ||
114 | |||
115 | SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen, | ||
116 | Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAllocPtr alloc); | ||
117 | |||
118 | EXTERN_C_END | ||
119 | |||
120 | #endif | ||