Fabcoin Core  0.16.2
P2P Digital Currency
gzip.h
Go to the documentation of this file.
1 // gzip.h - written and placed in the public domain by Wei Dai
2 
5 
6 #ifndef CRYPTOPP_GZIP_H
7 #define CRYPTOPP_GZIP_H
8 
9 #include "cryptlib.h"
10 #include "zdeflate.h"
11 #include "zinflate.h"
12 #include "crc.h"
13 
15 
16 class Gzip : public Deflator
19 {
20 public:
29  Gzip(BufferedTransformation *attachment=NULL, unsigned int deflateLevel=DEFAULT_DEFLATE_LEVEL, unsigned int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true)
30  : Deflator(attachment, deflateLevel, log2WindowSize, detectUncompressible), m_totalLen(0) {}
36  : Deflator(parameters, attachment), m_totalLen(0) {}
37 
38 protected:
39  enum {MAGIC1=0x1f, MAGIC2=0x8b, // flags for the header
40  DEFLATED=8, FAST=4, SLOW=2};
41 
42  void WritePrestreamHeader();
43  void ProcessUncompressedData(const byte *string, size_t length);
44  void WritePoststreamTail();
45 
48 };
49 
52 class Gunzip : public Inflator
53 {
54 public:
55  typedef Inflator::Err Err;
56 
59  class HeaderErr : public Err {public: HeaderErr() : Err(INVALID_DATA_FORMAT, "Gunzip: header decoding error") {}};
62  class TailErr : public Err {public: TailErr() : Err(INVALID_DATA_FORMAT, "Gunzip: tail too short") {}};
65  class CrcErr : public Err {public: CrcErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: CRC check error") {}};
68  class LengthErr : public Err {public: LengthErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: length check error") {}};
69 
74  Gunzip(BufferedTransformation *attachment = NULL, bool repeat = false, int autoSignalPropagation = -1);
75 
76 protected:
77  enum {
79  MAGIC1=0x1f,
81  MAGIC2=0x8b,
84  };
85 
86  enum FLAG_MASKS {
88 
89  unsigned int MaxPrestreamHeaderSize() const {return 1024;}
91  void ProcessDecompressedData(const byte *string, size_t length);
92  unsigned int MaxPoststreamTailSize() const {return 8;}
93  void ProcessPoststreamTail();
94 
97 };
98 
100 
101 #endif
Inflator::Err Err
Definition: gzip.h:55
uint8_t byte
Definition: Common.h:57
Second header magic value.
Definition: gzip.h:81
GZIP Decompression (RFC 1952)
Definition: gzip.h:52
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
void ProcessPoststreamTail()
Definition: gzip.cpp:84
word32 m_length
Definition: gzip.h:95
CRC32 m_crc
Definition: gzip.h:96
unsigned int MaxPrestreamHeaderSize() const
Definition: gzip.h:89
Abstract base classes that provide a uniform interface to this library.
Exception thrown when a CRC error occurs.
Definition: gzip.h:65
CRC32 m_crc
Definition: gzip.h:47
DEFLATE compressor (RFC 1951)
Definition: zdeflate.h:78
Exception thrown when a length error occurs.
Definition: gzip.h:68
Classes for CRC-32 and CRC-32C checksum algorithm.
Interface for buffered transformations.
Definition: cryptlib.h:1352
DEFLATE compression and decompression (RFC 1951)
unsigned int MaxPoststreamTailSize() const
Definition: gzip.h:92
Data integerity check, such as CRC or MAC, failed.
Definition: cryptlib.h:153
Gunzip(BufferedTransformation *attachment=NULL, bool repeat=false, int autoSignalPropagation=-1)
Construct a Gunzip decompressor.
Definition: gzip.cpp:39
word32 m_totalLen
Definition: gzip.h:46
Input data was received that did not conform to expected format.
Definition: cryptlib.h:155
Exception thrown when the tail is too short.
Definition: gzip.h:62
Exception thrown when a header decoding error occurs.
Definition: gzip.h:59
Gzip(const NameValuePairs &parameters, BufferedTransformation *attachment=NULL)
Construct a Gzip compressor.
Definition: gzip.h:35
FLAG_MASKS
Definition: gzip.h:86
void ProcessDecompressedData(const byte *string, size_t length)
Definition: gzip.cpp:77
DEFLATE decompressor (RFC 1951)
Definition: zinflate.h:92
Deflated flag.
Definition: gzip.h:83
Gzip(BufferedTransformation *attachment=NULL, unsigned int deflateLevel=DEFAULT_DEFLATE_LEVEL, unsigned int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true)
Construct a Gzip compressor.
Definition: gzip.h:29
First header magic value.
Definition: gzip.h:79
#define NAMESPACE_END
Definition: config.h:201
std::vector< char * > parameters
Definition: boostTest.cpp:46
GZIP Compression (RFC 1952)
Definition: gzip.h:18
Err(ErrorType e, const std::string &s)
Definition: zinflate.h:98
unsigned int word32
Definition: config.h:231
void ProcessPrestreamHeader()
Definition: gzip.cpp:44
CRC-32 Checksum Calculation.
Definition: crc.h:26
Interface for retrieving values given their names.
Definition: cryptlib.h:279