Lzma2Dec.h 3.8 KB

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