- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

# gzip.h

    00001 #ifndef CRYPTOPP_GZIP_H
    00002 #define CRYPTOPP_GZIP_H
    00003
    00004 #include "zdeflate.h"
    00005 #include "zinflate.h"
    00006 #include "crc.h"
    00007
    00008 NAMESPACE_BEGIN(CryptoPP)
    00009
    00010 /// GZIP Compression (RFC 1952)
    00011 class Gzip : public Deflator
    00012 {
    00013 public:
    00014         Gzip(BufferedTransformation *attachment=NULL, unsigned int deflateLevel=DEFAULT_DEFLATE_LEVEL, unsigned int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true)
    00015                 : Deflator(attachment, deflateLevel, log2WindowSize, detectUncompressible) {}
    00016         Gzip(const NameValuePairs &parameters, BufferedTransformation *attachment=NULL)
    00017                 : Deflator(parameters, attachment) {}
    00018
    00019 protected:
    00020         enum {MAGIC1=0x1f, MAGIC2=0x8b,   // flags for the header
    00021                   DEFLATED=8, FAST=4, SLOW=2};
    00022
    00023         void WritePrestreamHeader();
    00024         void ProcessUncompressedData(const byte *string, size_t length);
    00025         void WritePoststreamTail();
    00026
    00027         word32 m_totalLen;
    00028         CRC32 m_crc;
    00029 };
    00030
    00031 /// GZIP Decompression (RFC 1952)
    00032 class Gunzip : public Inflator
    00033 {
    00034 public:
    00035         typedef Inflator::Err Err;
    00036         class HeaderErr : public Err {public: HeaderErr() : Err(INVALID_DATA_FORMAT, "Gunzip: header decoding error") {}};
    00037         class TailErr : public Err {public: TailErr() : Err(INVALID_DATA_FORMAT, "Gunzip: tail too short") {}};
    00038         class CrcErr : public Err {public: CrcErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: CRC check error") {}};
    00039         class LengthErr : public Err {public: LengthErr() : Err(DATA_INTEGRITY_CHECK_FAILED, "Gunzip: length check error") {}};
    00040
    00041         /*! \param repeat decompress multiple compressed streams in series
    00042                 \param autoSignalPropagation 0 to turn off MessageEnd signal
    00043         */
    00044         Gunzip(BufferedTransformation *attachment = NULL, bool repeat = false, int autoSignalPropagation = -1);
    00045
    00046 protected:
    00047         enum {MAGIC1=0x1f, MAGIC2=0x8b,   // flags for the header
    00048                 DEFLATED=8};
    00049
    00050         enum FLAG_MASKS {
    00051                 CONTINUED=2, EXTRA_FIELDS=4, FILENAME=8, COMMENTS=16, ENCRYPTED=32};
    00052
    00053         unsigned int MaxPrestreamHeaderSize() const {return 1024;}
    00054         void ProcessPrestreamHeader();
    00055         void ProcessDecompressedData(const byte *string, size_t length);
    00056         unsigned int MaxPoststreamTailSize() const {return 8;}
    00057         void ProcessPoststreamTail();
    00058
    00059         word32 m_length;
    00060         CRC32 m_crc;
    00061 };
    00062
    00063 NAMESPACE_END
    00064
    00065 #endif