1 // LzmaDecoder.h 2 3 #ifndef ZIP7_INC_LZMA_DECODER_H 4 #define ZIP7_INC_LZMA_DECODER_H 5 6 // #include "../../../C/Alloc.h" 7 #include "../../../C/LzmaDec.h" 8 9 #include "../../Common/MyCom.h" 10 #include "../ICoder.h" 11 12 namespace NCompress { 13 namespace NLzma { 14 15 class CDecoder Z7_final: 16 public ICompressCoder, 17 public ICompressSetDecoderProperties2, 18 public ICompressSetFinishMode, 19 public ICompressGetInStreamProcessedSize, 20 public ICompressSetBufSize, 21 #ifndef Z7_NO_READ_FROM_CODER 22 public ICompressSetInStream, 23 public ICompressSetOutStreamSize, 24 public ISequentialInStream, 25 #endif 26 public CMyUnknownImp 27 { 28 Z7_COM_QI_BEGIN2(ICompressCoder) 29 Z7_COM_QI_ENTRY(ICompressSetDecoderProperties2) 30 Z7_COM_QI_ENTRY(ICompressSetFinishMode) 31 Z7_COM_QI_ENTRY(ICompressGetInStreamProcessedSize) 32 Z7_COM_QI_ENTRY(ICompressSetBufSize) 33 #ifndef Z7_NO_READ_FROM_CODER 34 Z7_COM_QI_ENTRY(ICompressSetInStream) 35 Z7_COM_QI_ENTRY(ICompressSetOutStreamSize) 36 Z7_COM_QI_ENTRY(ISequentialInStream) 37 #endif 38 Z7_COM_QI_END 39 Z7_COM_ADDREF_RELEASE 40 41 Z7_IFACE_COM7_IMP(ICompressCoder) 42 public: 43 Z7_IFACE_COM7_IMP(ICompressSetDecoderProperties2) 44 private: 45 Z7_IFACE_COM7_IMP(ICompressSetFinishMode) 46 Z7_IFACE_COM7_IMP(ICompressGetInStreamProcessedSize) 47 // Z7_IFACE_COM7_IMP(ICompressSetOutStreamSize) 48 49 Z7_IFACE_COM7_IMP(ICompressSetBufSize) 50 51 #ifndef Z7_NO_READ_FROM_CODER 52 public: 53 Z7_IFACE_COM7_IMP(ICompressSetInStream) 54 private: 55 Z7_IFACE_COM7_IMP(ISequentialInStream) 56 Z7_IFACE_COM7_IMP(ICompressSetOutStreamSize) 57 #else 58 Z7_COM7F_IMF(SetOutStreamSize(const UInt64 *outSize)); 59 #endif 60 61 public: 62 bool FinishStream; // set it before decoding, if you need to decode full LZMA stream 63 private: 64 bool _propsWereSet; 65 bool _outSizeDefined; 66 67 UInt32 _outStep; 68 UInt32 _inBufSize; 69 UInt32 _inBufSizeNew; 70 71 ELzmaStatus _lzmaStatus; 72 UInt32 _inPos; 73 UInt32 _inLim; 74 Byte *_inBuf; 75 76 UInt64 _outSize; 77 UInt64 _inProcessed; 78 UInt64 _outProcessed; 79 80 // CAlignOffsetAlloc _alloc; 81 82 CLzmaDec _state; 83 84 HRESULT CreateInputBuffer(); 85 HRESULT CodeSpec(ISequentialInStream *inStream, ISequentialOutStream *outStream, ICompressProgressInfo *progress); 86 void SetOutStreamSizeResume(const UInt64 *outSize); 87 88 #ifndef Z7_NO_READ_FROM_CODER 89 private: 90 CMyComPtr<ISequentialInStream> _inStream; 91 public: 92 HRESULT CodeResume(ISequentialOutStream *outStream, const UInt64 *outSize, ICompressProgressInfo *progress); 93 HRESULT ReadFromInputStream(void *data, UInt32 size, UInt32 *processedSize); 94 #endif 95 96 public: 97 CDecoder(); 98 ~CDecoder(); 99 GetInputProcessedSize()100 UInt64 GetInputProcessedSize() const { return _inProcessed; } GetOutputProcessedSize()101 UInt64 GetOutputProcessedSize() const { return _outProcessed; } NeedsMoreInput()102 bool NeedsMoreInput() const { return _lzmaStatus == LZMA_STATUS_NEEDS_MORE_INPUT; } CheckFinishStatus(bool withEndMark)103 bool CheckFinishStatus(bool withEndMark) const 104 { 105 return _lzmaStatus == (withEndMark ? 106 LZMA_STATUS_FINISHED_WITH_MARK : 107 LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK); 108 } 109 }; 110 111 }} 112 113 #endif 114