1 // LzmaDecoder.h 2 3 #ifndef __LZMA_DECODER_H 4 #define __LZMA_DECODER_H 5 6 #include "../../../C/LzmaDec.h" 7 8 #include "../../Common/MyCom.h" 9 #include "../ICoder.h" 10 11 namespace NCompress { 12 namespace NLzma { 13 14 class CDecoder: 15 public ICompressCoder, 16 public ICompressSetDecoderProperties2, 17 public ICompressSetFinishMode, 18 public ICompressSetBufSize, 19 #ifndef NO_READ_FROM_CODER 20 public ICompressSetInStream, 21 public ICompressSetOutStreamSize, 22 public ISequentialInStream, 23 #endif 24 public CMyUnknownImp 25 { 26 CMyComPtr<ISequentialInStream> _inStream; 27 Byte *_inBuf; 28 UInt32 _inPos; 29 UInt32 _inSize; 30 CLzmaDec _state; 31 bool _propsWereSet; 32 bool _outSizeDefined; 33 UInt64 _outSize; 34 UInt64 _inSizeProcessed; 35 UInt64 _outSizeProcessed; 36 37 UInt32 _inBufSizeAllocated; 38 UInt32 _inBufSize; 39 UInt32 _outBufSize; 40 SizeT _wrPos; 41 42 HRESULT CreateInputBuffer(); 43 HRESULT CodeSpec(ISequentialInStream *inStream, ISequentialOutStream *outStream, ICompressProgressInfo *progress); 44 void SetOutStreamSizeResume(const UInt64 *outSize); 45 46 public: 47 MY_QUERYINTERFACE_BEGIN2(ICompressCoder) 48 MY_QUERYINTERFACE_ENTRY(ICompressSetDecoderProperties2) 49 MY_QUERYINTERFACE_ENTRY(ICompressSetFinishMode) 50 MY_QUERYINTERFACE_ENTRY(ICompressSetBufSize) 51 #ifndef NO_READ_FROM_CODER 52 MY_QUERYINTERFACE_ENTRY(ICompressSetInStream) 53 MY_QUERYINTERFACE_ENTRY(ICompressSetOutStreamSize) 54 MY_QUERYINTERFACE_ENTRY(ISequentialInStream) 55 #endif 56 MY_QUERYINTERFACE_END 57 MY_ADDREF_RELEASE 58 59 STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream, 60 const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress); 61 STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size); 62 STDMETHOD(SetFinishMode)(UInt32 finishMode); 63 STDMETHOD(SetOutStreamSize)(const UInt64 *outSize); 64 STDMETHOD(SetInBufSize)(UInt32 streamIndex, UInt32 size); 65 STDMETHOD(SetOutBufSize)(UInt32 streamIndex, UInt32 size); 66 67 #ifndef NO_READ_FROM_CODER 68 69 STDMETHOD(SetInStream)(ISequentialInStream *inStream); 70 STDMETHOD(ReleaseInStream)(); 71 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize); 72 73 HRESULT CodeResume(ISequentialOutStream *outStream, const UInt64 *outSize, ICompressProgressInfo *progress); 74 HRESULT ReadFromInputStream(void *data, UInt32 size, UInt32 *processedSize); 75 UInt64 GetInputProcessedSize() const { return _inSizeProcessed; } 76 77 #endif 78 79 bool FinishStream; // set it before decoding, if you need to decode full LZMA stream 80 81 bool NeedMoreInput; // it's set by decoder, if it needs more input data to decode stream 82 83 CDecoder(); 84 virtual ~CDecoder(); 85 86 UInt64 GetOutputProcessedSize() const { return _outSizeProcessed; } 87 }; 88 89 }} 90 91 #endif 92