1 /* LzmaDec.h -- LZMA Decoder
2 2009-02-07 : Igor Pavlov : Public domain */
13 /* #define _LZMA_PROB32 */
14 /* _LZMA_PROB32 can increase the speed on some CPUs,
15 but memory usage for CLzmaDec::probs will be doubled in that case */
18 #define CLzmaProb UInt32
20 #define CLzmaProb UInt16
24 /* ---------- LZMA Properties ---------- */
26 #define LZMA_PROPS_SIZE 5
28 typedef struct _CLzmaProps
34 /* LzmaProps_Decode - decodes properties
37 SZ_ERROR_UNSUPPORTED - Unsupported properties
40 SRes
LzmaProps_Decode(CLzmaProps
*p
, const Byte
*data
, unsigned size
);
43 /* ---------- LZMA Decoder state ---------- */
45 /* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
46 Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
48 #define LZMA_REQUIRED_INPUT_MAX 20
68 Byte tempBuf
[LZMA_REQUIRED_INPUT_MAX
];
71 #define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
73 void LzmaDec_Init(CLzmaDec
*p
);
75 /* There are two types of LZMA streams:
76 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
77 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
81 LZMA_FINISH_ANY
, /* finish at any point */
82 LZMA_FINISH_END
/* block must be finished at the end */
85 /* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
87 You must use LZMA_FINISH_END, when you know that current output buffer
88 covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
90 If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
91 and output value of destLen will be less than output buffer size limit.
92 You can check status result also.
94 You can use multiple checks to test data integrity after full decompression:
95 1) Check Result and "status" variable.
96 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
97 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
98 You must use correct finish mode in that case. */
102 LZMA_STATUS_NOT_SPECIFIED
, /* use main error code instead */
103 LZMA_STATUS_FINISHED_WITH_MARK
, /* stream was finished with end mark. */
104 LZMA_STATUS_NOT_FINISHED
, /* stream was not finished */
105 LZMA_STATUS_NEEDS_MORE_INPUT
, /* you must provide more input bytes */
106 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
/* there is probability that stream was finished without end mark */
109 /* ELzmaStatus is used only as output value for function call */
112 /* ---------- Interfaces ---------- */
114 /* There are 3 levels of interfaces:
115 1) Dictionary Interface
117 3) One Call Interface
118 You can select any of these interfaces, but don't mix functions from different
119 groups for same object. */
122 /* There are two variants to allocate state for Dictionary Interface:
123 1) LzmaDec_Allocate / LzmaDec_Free
124 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
125 You can use variant 2, if you set dictionary buffer manually.
126 For Buffer Interface you must always use variant 1.
128 LzmaDec_Allocate* can return:
130 SZ_ERROR_MEM - Memory allocation error
131 SZ_ERROR_UNSUPPORTED - Unsupported properties
134 SRes
LzmaDec_AllocateProbs(CLzmaDec
*p
, const Byte
*props
, unsigned propsSize
, ISzAlloc
*alloc
);
135 void LzmaDec_FreeProbs(CLzmaDec
*p
, ISzAlloc
*alloc
);
137 SRes
LzmaDec_Allocate(CLzmaDec
*state
, const Byte
*prop
, unsigned propsSize
, ISzAlloc
*alloc
);
138 void LzmaDec_Free(CLzmaDec
*state
, ISzAlloc
*alloc
);
140 /* ---------- Dictionary Interface ---------- */
142 /* You can use it, if you want to eliminate the overhead for data copying from
143 dictionary to some other external buffer.
144 You must work with CLzmaDec variables directly in this interface.
149 for (each new stream)
152 while (it needs more decompression)
154 LzmaDec_DecodeToDic()
155 use data from CLzmaDec::dic and update CLzmaDec::dicPos
161 /* LzmaDec_DecodeToDic
163 The decoding to internal dictionary buffer (CLzmaDec::dic).
164 You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
167 It has meaning only if the decoding reaches output limit (dicLimit).
168 LZMA_FINISH_ANY - Decode just dicLimit bytes.
169 LZMA_FINISH_END - Stream must be finished after dicLimit.
174 LZMA_STATUS_FINISHED_WITH_MARK
175 LZMA_STATUS_NOT_FINISHED
176 LZMA_STATUS_NEEDS_MORE_INPUT
177 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
178 SZ_ERROR_DATA - Data error
181 SRes
LzmaDec_DecodeToDic(CLzmaDec
*p
, SizeT dicLimit
,
182 const Byte
*src
, SizeT
*srcLen
, ELzmaFinishMode finishMode
, ELzmaStatus
*status
);
185 /* ---------- Buffer Interface ---------- */
187 /* It's zlib-like interface.
188 See LzmaDec_DecodeToDic description for information about STEPS and return results,
189 but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
190 to work with CLzmaDec variables manually.
193 It has meaning only if the decoding reaches output limit (*destLen).
194 LZMA_FINISH_ANY - Decode just destLen bytes.
195 LZMA_FINISH_END - Stream must be finished after (*destLen).
198 SRes
LzmaDec_DecodeToBuf(CLzmaDec
*p
, Byte
*dest
, SizeT
*destLen
,
199 const Byte
*src
, SizeT
*srcLen
, ELzmaFinishMode finishMode
, ELzmaStatus
*status
);
202 /* ---------- One Call Interface ---------- */
207 It has meaning only if the decoding reaches output limit (*destLen).
208 LZMA_FINISH_ANY - Decode just destLen bytes.
209 LZMA_FINISH_END - Stream must be finished after (*destLen).
214 LZMA_STATUS_FINISHED_WITH_MARK
215 LZMA_STATUS_NOT_FINISHED
216 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
217 SZ_ERROR_DATA - Data error
218 SZ_ERROR_MEM - Memory allocation error
219 SZ_ERROR_UNSUPPORTED - Unsupported properties
220 SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
223 SRes
LzmaDecode(Byte
*dest
, SizeT
*destLen
, const Byte
*src
, SizeT
*srcLen
,
224 const Byte
*propData
, unsigned propSize
, ELzmaFinishMode finishMode
,
225 ELzmaStatus
*status
, ISzAlloc
*alloc
);