1 #ifndef CRYPTOPP_ZDEFLATE_H
2 #define CRYPTOPP_ZDEFLATE_H
7 NAMESPACE_BEGIN(CryptoPP)
14 void PutBits(
unsigned long value,
unsigned int length);
15 void FlushBitBuffer();
16 void ClearBitBuffer();
19 unsigned long FinishCounting();
23 unsigned long m_bitCount;
24 unsigned long m_buffer;
25 unsigned int m_bitsBuffered, m_bytesBuffered;
33 typedef unsigned int code_t;
34 typedef unsigned int value_t;
38 void Initialize(
const unsigned int *codeBits,
unsigned int nCodes);
40 static void GenerateCodeLengths(
unsigned int *codeBits,
unsigned int maxCodeBits,
const unsigned int *codeCounts,
size_t nCodes);
58 enum {MIN_DEFLATE_LEVEL = 0, DEFAULT_DEFLATE_LEVEL = 6, MAX_DEFLATE_LEVEL = 9};
59 enum {MIN_LOG2_WINDOW_SIZE = 9, DEFAULT_LOG2_WINDOW_SIZE = 15, MAX_LOG2_WINDOW_SIZE = 15};
63 Deflator(
BufferedTransformation *attachment=NULL,
int deflateLevel=DEFAULT_DEFLATE_LEVEL,
int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE,
bool detectUncompressible=
true);
69 int GetDeflateLevel()
const {
return m_deflateLevel;}
70 int GetLog2WindowSize()
const {
return m_log2WindowSize;}
73 size_t Put2(
const byte *inString,
size_t length,
int messageEnd,
bool blocking);
74 bool IsolatedFlush(
bool hardFlush,
bool blocking);
77 virtual void WritePrestreamHeader() {}
78 virtual void ProcessUncompressedData(
const byte *
string,
size_t length) {}
79 virtual void WritePoststreamTail() {}
81 enum {STORED = 0, STATIC = 1, DYNAMIC = 2};
82 enum {MIN_MATCH = 3, MAX_MATCH = 258};
84 void InitializeStaticEncoders();
85 void Reset(
bool forceReset =
false);
86 unsigned int FillWindow(
const byte *str,
size_t length);
87 unsigned int ComputeHash(
const byte *str)
const;
88 unsigned int LongestMatch(
unsigned int &bestMatch)
const;
89 void InsertString(
unsigned int start);
92 void LiteralByte(byte b);
93 void MatchFound(
unsigned int distance,
unsigned int length);
94 void EncodeBlock(
bool eof,
unsigned int blockType);
95 void EndBlock(
bool eof);
99 unsigned literalCode : 9;
100 unsigned literalExtra : 5;
101 unsigned distanceCode : 5;
102 unsigned distanceExtra : 13;
105 int m_deflateLevel, m_log2WindowSize, m_compressibleDeflateLevel;
106 unsigned int m_detectSkip, m_detectCount;
107 unsigned int DSIZE, DMASK, HSIZE, HMASK, GOOD_MATCH, MAX_LAZYLENGTH, MAX_CHAIN_LENGTH;
108 bool m_headerWritten, m_matchAvailable;
109 unsigned int m_dictionaryEnd, m_stringStart, m_lookahead, m_minLookahead, m_previousMatch, m_previousLength;
110 HuffmanEncoder m_staticLiteralEncoder, m_staticDistanceEncoder, m_dynamicLiteralEncoder, m_dynamicDistanceEncoder;
116 unsigned int m_matchBufferEnd, m_blockStart, m_blockLength;
a block of memory allocated using A
DEFLATE (RFC 1951) compressor.
void SetDeflateLevel(int deflateLevel)
this function can be used to set the deflate level in the middle of compression
Deflator(BufferedTransformation *attachment=NULL, int deflateLevel=DEFAULT_DEFLATE_LEVEL, int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true)
provides an implementation of BufferedTransformation's attachment interface
size_t Put2(const byte *inString, size_t length, int messageEnd, bool blocking)
input multiple bytes for blocking or non-blocking processing
interface for retrieving values given their names