16 static const byte DEFLATE_METHOD = 8;
17 static const byte FDICT_FLAG = (1 << 5);
21 void ZlibCompressor::WritePrestreamHeader()
26 assert((GetCompressionLevel() << 6) <= 255);
27 byte flags = byte(GetCompressionLevel() << 6);
31 void ZlibCompressor::ProcessUncompressedData(
const byte *inString,
size_t length)
33 m_adler32.
Update(inString, length);
36 void ZlibCompressor::WritePoststreamTail()
39 m_adler32.
Final(adler32);
43 unsigned int ZlibCompressor::GetCompressionLevel()
const
45 static const unsigned int deflateToCompressionLevel[] = {0, 1, 1, 1, 2, 2, 2, 2, 2, 3};
52 :
Inflator(attachment, repeat, propagation), m_log2WindowSize(0)
56 void ZlibDecompressor::ProcessPrestreamHeader()
63 if (!m_inQueue.Get(cmf) || !m_inQueue.Get(flags))
66 if ((cmf*256+flags) % 31 != 0)
69 if ((cmf & 0xf) != DEFLATE_METHOD)
70 throw UnsupportedAlgorithm();
72 if (flags & FDICT_FLAG)
73 throw UnsupportedPresetDictionary();
75 m_log2WindowSize = 8 + (cmf >> 4);
78 void ZlibDecompressor::ProcessDecompressedData(
const byte *inString,
size_t length)
81 m_adler32.
Update(inString, length);
84 void ZlibDecompressor::ProcessPoststreamTail()
87 if (m_inQueue.Get(adler32, 4) != 4)
89 if (!m_adler32.
Verify(adler32))