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 ICompressSetBufSize,
18   #ifndef NO_READ_FROM_CODER
19   public ICompressSetInStream,
20   public ICompressSetOutStreamSize,
21   public ISequentialInStream,
22   #endif
23   public CMyUnknownImp
24 {
25   CMyComPtr<ISequentialInStream> _inStream;
26   Byte *_inBuf;
27   UInt32 _inPos;
28   UInt32 _inSize;
29   CLzmaDec _state;
30   bool _propsWereSet;
31   bool _outSizeDefined;
32   UInt64 _outSize;
33   UInt64 _inSizeProcessed;
34   UInt64 _outSizeProcessed;
35 
36   UInt32 _inBufSizeAllocated;
37   UInt32 _inBufSize;
38   UInt32 _outBufSize;
39   SizeT _wrPos;
40 
41   HRESULT CreateInputBuffer();
42   HRESULT CodeSpec(ISequentialInStream *inStream, ISequentialOutStream *outStream, ICompressProgressInfo *progress);
43   void SetOutStreamSizeResume(const UInt64 *outSize);
44 
45 public:
46   MY_QUERYINTERFACE_BEGIN2(ICompressCoder)
47   MY_QUERYINTERFACE_ENTRY(ICompressSetDecoderProperties2)
48   MY_QUERYINTERFACE_ENTRY(ICompressSetBufSize)
49   #ifndef NO_READ_FROM_CODER
50   MY_QUERYINTERFACE_ENTRY(ICompressSetInStream)
51   MY_QUERYINTERFACE_ENTRY(ICompressSetOutStreamSize)
52   MY_QUERYINTERFACE_ENTRY(ISequentialInStream)
53   #endif
54   MY_QUERYINTERFACE_END
55   MY_ADDREF_RELEASE
56 
57   STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
58       const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
59   STDMETHOD(SetDecoderProperties2)(const Byte *data, UInt32 size);
60   STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
61   STDMETHOD(SetInBufSize)(UInt32 streamIndex, UInt32 size);
62   STDMETHOD(SetOutBufSize)(UInt32 streamIndex, UInt32 size);
63 
64   #ifndef NO_READ_FROM_CODER
65 
66   STDMETHOD(SetInStream)(ISequentialInStream *inStream);
67   STDMETHOD(ReleaseInStream)();
68   STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
69 
70   HRESULT CodeResume(ISequentialOutStream *outStream, const UInt64 *outSize, ICompressProgressInfo *progress);
71   HRESULT ReadFromInputStream(void *data, UInt32 size, UInt32 *processedSize);
GetInputProcessedSize()72   UInt64 GetInputProcessedSize() const { return _inSizeProcessed; }
73 
74   #endif
75 
76   bool FinishStream;
77 
78   CDecoder();
79   virtual ~CDecoder();
80 };
81 
82 }}
83 
84 #endif
85