13 NAMESPACE_BEGIN(CryptoPP)
15 static const byte DEFLATE_METHOD = 8;
16 static const byte FDICT_FLAG = 1 << 5;
23 byte cmf = DEFLATE_METHOD | ((GetLog2WindowSize()-8) << 4);
24 byte flags = GetCompressionLevel() << 6;
25 AttachedTransformation()->
PutWord16(RoundUpToMultipleOf(cmf*256+flags, 31));
28 void ZlibCompressor::ProcessUncompressedData(
const byte *inString,
size_t length)
30 m_adler32.
Update(inString, length);
33 void ZlibCompressor::WritePoststreamTail()
36 m_adler32.
Final(adler32);
40 unsigned int ZlibCompressor::GetCompressionLevel()
const
42 static const unsigned int deflateToCompressionLevel[] = {0, 1, 1, 1, 2, 2, 2, 2, 2, 3};
43 return deflateToCompressionLevel[GetDeflateLevel()];
49 :
Inflator(attachment, repeat, propagation)
53 void ZlibDecompressor::ProcessPrestreamHeader()
60 if (!m_inQueue.
Get(cmf) || !m_inQueue.
Get(flags))
63 if ((cmf*256+flags) % 31 != 0)
66 if ((cmf & 0xf) != DEFLATE_METHOD)
67 throw UnsupportedAlgorithm();
69 if (flags & FDICT_FLAG)
70 throw UnsupportedPresetDictionary();
72 m_log2WindowSize = 8 + (cmf >> 4);
75 void ZlibDecompressor::ProcessDecompressedData(
const byte *inString,
size_t length)
78 m_adler32.
Update(inString, length);
81 void ZlibDecompressor::ProcessPoststreamTail()
84 if (m_inQueue.
Get(adler32, 4) != 4)
86 if (!m_adler32.
Verify(adler32))