Lzma2Dec.h 3.7 KB

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