view src/win32/7zip/7z/CPP/7zip/Compress/DeflateDecoder.h @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line source
1 // DeflateDecoder.h
3 #ifndef __DEFLATE_DECODER_H
4 #define __DEFLATE_DECODER_H
6 #include "../../Common/MyCom.h"
8 #include "../ICoder.h"
10 #include "../Common/InBuffer.h"
12 #include "BitlDecoder.h"
13 #include "DeflateConst.h"
14 #include "HuffmanDecoder.h"
15 #include "LzOutWindow.h"
17 namespace NCompress {
18 namespace NDeflate {
19 namespace NDecoder {
21 class CCoder:
22 public ICompressCoder,
23 public ICompressGetInStreamProcessedSize,
24 #ifndef NO_READ_FROM_CODER
25 public ICompressSetInStream,
26 public ICompressSetOutStreamSize,
27 public ISequentialInStream,
28 #endif
29 public CMyUnknownImp
30 {
31 CLzOutWindow m_OutWindowStream;
32 NBitl::CDecoder<CInBuffer> m_InBitStream;
33 NCompress::NHuffman::CDecoder<kNumHuffmanBits, kFixedMainTableSize> m_MainDecoder;
34 NCompress::NHuffman::CDecoder<kNumHuffmanBits, kFixedDistTableSize> m_DistDecoder;
35 NCompress::NHuffman::CDecoder<kNumHuffmanBits, kLevelTableSize> m_LevelDecoder;
37 UInt32 m_StoredBlockSize;
39 bool m_FinalBlock;
40 bool m_StoredMode;
41 UInt32 _numDistLevels;
44 bool _deflateNSIS;
45 bool _deflate64Mode;
46 bool _keepHistory;
47 Int32 _remainLen;
48 UInt32 _rep0;
49 bool _needReadTable;
51 UInt32 ReadBits(int numBits);
53 bool DeCodeLevelTable(Byte *values, int numSymbols);
54 bool ReadTables();
56 void ReleaseStreams()
57 {
58 m_OutWindowStream.ReleaseStream();
59 ReleaseInStream();
60 }
62 HRESULT Flush() { return m_OutWindowStream.Flush(); }
63 class CCoderReleaser
64 {
65 CCoder *m_Coder;
66 public:
67 bool NeedFlush;
68 CCoderReleaser(CCoder *coder): m_Coder(coder), NeedFlush(true) {}
69 ~CCoderReleaser()
70 {
71 if (NeedFlush)
72 m_Coder->Flush();
73 m_Coder->ReleaseStreams();
74 }
75 };
76 friend class CCoderReleaser;
78 HRESULT CodeSpec(UInt32 curSize);
79 public:
80 bool ZlibMode;
81 Byte ZlibFooter[4];
83 CCoder(bool deflate64Mode, bool deflateNSIS = false);
84 void SetKeepHistory(bool keepHistory) { _keepHistory = keepHistory; }
86 HRESULT CodeReal(ISequentialInStream *inStream, ISequentialOutStream *outStream,
87 const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
89 #ifndef NO_READ_FROM_CODER
90 MY_UNKNOWN_IMP4(
91 ICompressGetInStreamProcessedSize,
92 ICompressSetInStream,
93 ICompressSetOutStreamSize,
94 ISequentialInStream
95 )
96 #else
97 MY_UNKNOWN_IMP1(
98 ICompressGetInStreamProcessedSize)
99 #endif
101 STDMETHOD(Code)(ISequentialInStream *inStream, ISequentialOutStream *outStream,
102 const UInt64 *inSize, const UInt64 *outSize, ICompressProgressInfo *progress);
104 STDMETHOD(SetInStream)(ISequentialInStream *inStream);
105 STDMETHOD(ReleaseInStream)();
106 STDMETHOD(SetOutStreamSize)(const UInt64 *outSize);
108 #ifndef NO_READ_FROM_CODER
109 STDMETHOD(Read)(void *data, UInt32 size, UInt32 *processedSize);
110 #endif
112 // IGetInStreamProcessedSize
113 STDMETHOD(GetInStreamProcessedSize)(UInt64 *value);
114 };
116 class CCOMCoder : public CCoder
117 {
118 public:
119 CCOMCoder(): CCoder(false) {}
120 };
122 class CNsisCOMCoder : public CCoder
123 {
124 public:
125 CNsisCOMCoder(): CCoder(false, true) {}
126 };
128 class CCOMCoder64 : public CCoder
129 {
130 public:
131 CCOMCoder64(): CCoder(true) {}
132 };
134 }}}
136 #endif