1 /* LzmaDec.h -- LZMA Decoder
2 2009-02-07 : Igor Pavlov : Public domain */
9 /* #define _LZMA_PROB32 */
10 /* _LZMA_PROB32 can increase the speed on some CPUs,
11 but memory usage for CLzmaDec::probs will be doubled in that case */
14 #define CLzmaProb UInt32
16 #define CLzmaProb UInt16
19 /* ---------- LZMA Properties ---------- */
21 #define LZMA_PROPS_SIZE 5
23 typedef struct _CLzmaProps
29 /* LzmaProps_Decode - decodes properties
32 SZ_ERROR_UNSUPPORTED - Unsupported properties
35 SRes
LzmaProps_Decode(CLzmaProps
*p
, const Byte
*data
, unsigned size
);
37 /* ---------- LZMA Decoder state ---------- */
39 /* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
40 Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
42 #define LZMA_REQUIRED_INPUT_MAX 20
62 Byte tempBuf
[LZMA_REQUIRED_INPUT_MAX
];
65 #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
67 void LzmaDec_Init(CLzmaDec
*p
);
69 /* There are two types of LZMA streams:
70 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
71 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
75 LZMA_FINISH_ANY
, /* finish at any point */
76 LZMA_FINISH_END
/* block must be finished at the end */
79 /* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
81 You must use LZMA_FINISH_END, when you know that current output buffer
82 covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
84 If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
85 and output value of destLen will be less than output buffer size limit.
86 You can check status result also.
88 You can use multiple checks to test data integrity after full decompression:
89 1) Check Result and "status" variable.
90 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
91 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
92 You must use correct finish mode in that case. */
96 LZMA_STATUS_NOT_SPECIFIED
, /* use main error code instead */
97 LZMA_STATUS_FINISHED_WITH_MARK
, /* stream was finished with end mark. */
98 LZMA_STATUS_NOT_FINISHED
, /* stream was not finished */
99 LZMA_STATUS_NEEDS_MORE_INPUT
, /* you must provide more input bytes */
100 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
/* there is probability that stream was finished without end mark */
103 /* ELzmaStatus is used only as output value for function call */
105 /* ---------- Interfaces ---------- */
107 /* There are 3 levels of interfaces:
108 1) Dictionary Interface
110 3) One Call Interface
111 You can select any of these interfaces, but don't mix functions from different
112 groups for same object. */
114 /* There are two variants to allocate state for Dictionary Interface:
115 1) LzmaDec_Allocate / LzmaDec_Free
116 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
117 You can use variant 2, if you set dictionary buffer manually.
118 For Buffer Interface you must always use variant 1.
120 LzmaDec_Allocate* can return:
122 SZ_ERROR_MEM - Memory allocation error
123 SZ_ERROR_UNSUPPORTED - Unsupported properties
126 SRes
LzmaDec_AllocateProbs(CLzmaDec
*p
, const Byte
*props
, unsigned propsSize
, ISzAlloc
*alloc
);
127 void LzmaDec_FreeProbs(CLzmaDec
*p
, ISzAlloc
*alloc
);
129 SRes
LzmaDec_Allocate(CLzmaDec
*state
, const Byte
*prop
, unsigned propsSize
, ISzAlloc
*alloc
);
130 void LzmaDec_Free(CLzmaDec
*state
, ISzAlloc
*alloc
);
132 /* ---------- Dictionary Interface ---------- */
134 /* You can use it, if you want to eliminate the overhead for data copying from
135 dictionary to some other external buffer.
136 You must work with CLzmaDec variables directly in this interface.
141 for (each new stream)
144 while (it needs more decompression)
146 LzmaDec_DecodeToDic()
147 use data from CLzmaDec::dic and update CLzmaDec::dicPos
153 /* LzmaDec_DecodeToDic
155 The decoding to internal dictionary buffer (CLzmaDec::dic).
156 You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
159 It has meaning only if the decoding reaches output limit (dicLimit).
160 LZMA_FINISH_ANY - Decode just dicLimit bytes.
161 LZMA_FINISH_END - Stream must be finished after dicLimit.
166 LZMA_STATUS_FINISHED_WITH_MARK
167 LZMA_STATUS_NOT_FINISHED
168 LZMA_STATUS_NEEDS_MORE_INPUT
169 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
170 SZ_ERROR_DATA - Data error
173 SRes
LzmaDec_DecodeToDic(CLzmaDec
*p
, SizeT dicLimit
,
174 const Byte
*src
, SizeT
*srcLen
, ELzmaFinishMode finishMode
, ELzmaStatus
*status
);
176 /* ---------- Buffer Interface ---------- */
178 /* It's zlib-like interface.
179 See LzmaDec_DecodeToDic description for information about STEPS and return results,
180 but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
181 to work with CLzmaDec variables manually.
184 It has meaning only if the decoding reaches output limit (*destLen).
185 LZMA_FINISH_ANY - Decode just destLen bytes.
186 LZMA_FINISH_END - Stream must be finished after (*destLen).
189 SRes
LzmaDec_DecodeToBuf(CLzmaDec
*p
, Byte
*dest
, SizeT
*destLen
,
190 const Byte
*src
, SizeT
*srcLen
, ELzmaFinishMode finishMode
, ELzmaStatus
*status
);
192 /* ---------- One Call Interface ---------- */
197 It has meaning only if the decoding reaches output limit (*destLen).
198 LZMA_FINISH_ANY - Decode just destLen bytes.
199 LZMA_FINISH_END - Stream must be finished after (*destLen).
204 LZMA_STATUS_FINISHED_WITH_MARK
205 LZMA_STATUS_NOT_FINISHED
206 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
207 SZ_ERROR_DATA - Data error
208 SZ_ERROR_MEM - Memory allocation error
209 SZ_ERROR_UNSUPPORTED - Unsupported properties
210 SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
213 SRes
LzmaDecode(Byte
*dest
, SizeT
*destLen
, const Byte
*src
, SizeT
*srcLen
,
214 const Byte
*propData
, unsigned propSize
, ELzmaFinishMode finishMode
,
215 ELzmaStatus
*status
, ISzAlloc
*alloc
);