/* Lzma2Dec.h -- LZMA2 Decoder12023-03-03 : Igor Pavlov : Public domain */23#ifndef ZIP7_INC_LZMA2_DEC_H4#define ZIP7_INC_LZMA2_DEC_H56#include "LzmaDec.h"78EXTERN_C_BEGIN910/* ---------- State Interface ---------- */1112typedef struct13{14unsigned state;15Byte control;16Byte needInitLevel;17Byte isExtraMode;18Byte _pad_;19UInt32 packSize;20UInt32 unpackSize;21CLzmaDec decoder;22} CLzma2Dec;2324#define Lzma2Dec_CONSTRUCT(p) LzmaDec_CONSTRUCT(&(p)->decoder)25#define Lzma2Dec_Construct(p) Lzma2Dec_CONSTRUCT(p)26#define Lzma2Dec_FreeProbs(p, alloc) LzmaDec_FreeProbs(&(p)->decoder, alloc)27#define Lzma2Dec_Free(p, alloc) LzmaDec_Free(&(p)->decoder, alloc)2829SRes Lzma2Dec_AllocateProbs(CLzma2Dec *p, Byte prop, ISzAllocPtr alloc);30SRes Lzma2Dec_Allocate(CLzma2Dec *p, Byte prop, ISzAllocPtr alloc);31void Lzma2Dec_Init(CLzma2Dec *p);3233/*34finishMode:35It has meaning only if the decoding reaches output limit (*destLen or dicLimit).36LZMA_FINISH_ANY - use smallest number of input bytes37LZMA_FINISH_END - read EndOfStream marker after decoding3839Returns:40SZ_OK41status:42LZMA_STATUS_FINISHED_WITH_MARK43LZMA_STATUS_NOT_FINISHED44LZMA_STATUS_NEEDS_MORE_INPUT45SZ_ERROR_DATA - Data error46*/4748SRes Lzma2Dec_DecodeToDic(CLzma2Dec *p, SizeT dicLimit,49const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);5051SRes Lzma2Dec_DecodeToBuf(CLzma2Dec *p, Byte *dest, SizeT *destLen,52const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);535455/* ---------- LZMA2 block and chunk parsing ---------- */5657/*58Lzma2Dec_Parse() parses compressed data stream up to next independent block or next chunk data.59It 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.62CLzma2Dec::unpackSize contains unpack size of that chunk63*/6465typedef enum66{67/*68LZMA_STATUS_NOT_SPECIFIED // data error69LZMA_STATUS_FINISHED_WITH_MARK70LZMA_STATUS_NOT_FINISHED //71LZMA_STATUS_NEEDS_MORE_INPUT72LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK // unused73*/74LZMA2_PARSE_STATUS_NEW_BLOCK = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK + 1,75LZMA2_PARSE_STATUS_NEW_CHUNK76} ELzma2ParseStatus;7778ELzma2ParseStatus Lzma2Dec_Parse(CLzma2Dec *p,79SizeT outSize, // output size80const Byte *src, SizeT *srcLen,81int checkFinishBlock // set (checkFinishBlock = 1), if it must read full input data, if decoder.dicPos reaches blockMax position.82);8384/*85LZMA2 parser doesn't decode LZMA chunks, so we must read86full input LZMA chunk to decode some part of LZMA chunk.8788Lzma2Dec_GetUnpackExtra() returns the value that shows89max possible number of output bytes that can be output by decoder90at current input positon.91*/9293#define Lzma2Dec_GetUnpackExtra(p) ((p)->isExtraMode ? (p)->unpackSize : 0)949596/* ---------- One Call Interface ---------- */9798/*99finishMode:100It has meaning only if the decoding reaches output limit (*destLen).101LZMA_FINISH_ANY - use smallest number of input bytes102LZMA_FINISH_END - read EndOfStream marker after decoding103104Returns:105SZ_OK106status:107LZMA_STATUS_FINISHED_WITH_MARK108LZMA_STATUS_NOT_FINISHED109SZ_ERROR_DATA - Data error110SZ_ERROR_MEM - Memory allocation error111SZ_ERROR_UNSUPPORTED - Unsupported properties112SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).113*/114115SRes Lzma2Decode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,116Byte prop, ELzmaFinishMode finishMode, ELzmaStatus *status, ISzAllocPtr alloc);117118EXTERN_C_END119120#endif121122123