Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: gzip.h
- ===================================================================
- --- gzip.h (revision 541)
- +++ gzip.h (working copy)
- @@ -12,13 +12,20 @@
- {
- public:
- Gzip(BufferedTransformation *attachment=NULL, unsigned int deflateLevel=DEFAULT_DEFLATE_LEVEL, unsigned int log2WindowSize=DEFAULT_LOG2_WINDOW_SIZE, bool detectUncompressible=true)
- - : Deflator(attachment, deflateLevel, log2WindowSize, detectUncompressible) {}
- + : Deflator(attachment, deflateLevel, log2WindowSize, detectUncompressible), m_filetime(0) {}
- Gzip(const NameValuePairs ¶meters, BufferedTransformation *attachment=NULL)
- - : Deflator(parameters, attachment) {}
- + : Deflator(parameters, attachment), m_filetime(0) {}
- +
- + void SetFiletime(word32 filetime) { m_filetime = filetime; }
- + void SetFilename(const std::string& filename) { m_filename = filename; }
- + void SetComment(const std::string& comment) { m_comment = comment; }
- protected:
- enum {MAGIC1=0x1f, MAGIC2=0x8b, // flags for the header
- DEFLATED=8, FAST=4, SLOW=2};
- +
- + enum FLAG_MASKS {
- + FILENAME=8, COMMENTS=16};
- void WritePrestreamHeader();
- void ProcessUncompressedData(const byte *string, size_t length);
- @@ -26,6 +33,10 @@
- word32 m_totalLen;
- CRC32 m_crc;
- +
- + word32 m_filetime;
- + std::string m_filename;
- + std::string m_comment;
- };
- /// GZIP Decompression (RFC 1952)
- @@ -42,6 +53,10 @@
- \param autoSignalPropagation 0 to turn off MessageEnd signal
- */
- Gunzip(BufferedTransformation *attachment = NULL, bool repeat = false, int autoSignalPropagation = -1);
- +
- + word32 GetFiletime() const { return m_filetime; }
- + const std::string& GetFilename() const { return m_filename; }
- + const std::string& GetComment() const { return m_comment; }
- protected:
- enum {MAGIC1=0x1f, MAGIC2=0x8b, // flags for the header
- @@ -58,6 +73,10 @@
- word32 m_length;
- CRC32 m_crc;
- +
- + word32 m_filetime;
- + std::string m_filename;
- + std::string m_comment;
- };
- NAMESPACE_END
- Index: gzip.cpp
- ===================================================================
- --- gzip.cpp (revision 541)
- +++ gzip.cpp (working copy)
- @@ -9,15 +9,27 @@
- {
- m_totalLen = 0;
- m_crc.Restart();
- +
- + word32 flags = 0;
- + if(!m_filename.empty())
- + flags |= FILENAME;
- + if(!m_comment.empty())
- + flags |= COMMENTS;
- AttachedTransformation()->Put(MAGIC1);
- AttachedTransformation()->Put(MAGIC2);
- AttachedTransformation()->Put(DEFLATED);
- - AttachedTransformation()->Put(0); // general flag
- - AttachedTransformation()->PutWord32(0); // time stamp
- - byte extra = (GetDeflateLevel() == 1) ? FAST : ((GetDeflateLevel() == 9) ? SLOW : 0);
- + AttachedTransformation()->Put(flags); // general flag
- + AttachedTransformation()->PutWord32(m_filetime); // time stamp
- + byte extra = (GetDeflateLevel() == 1) ? FAST : ((GetDeflateLevel() == 9) ? SLOW : 0);
- AttachedTransformation()->Put(extra);
- - AttachedTransformation()->Put(GZIP_OS_CODE);
- + AttachedTransformation()->Put(GZIP_OS_CODE);
- +
- + if(!m_filename.empty())
- + AttachedTransformation()->Put((const unsigned char*)m_filename.data(), m_filename.size() +1);
- +
- + if(!m_comment.empty())
- + AttachedTransformation()->Put((const unsigned char*)m_comment.data(), m_comment.size() +1);
- }
- void Gzip::ProcessUncompressedData(const byte *inString, size_t length)
- @@ -37,7 +49,7 @@
- // *************************************************************
- Gunzip::Gunzip(BufferedTransformation *attachment, bool repeat, int propagation)
- - : Inflator(attachment, repeat, propagation)
- + : Inflator(attachment, repeat, propagation), m_filetime(0)
- {
- }
- @@ -45,16 +57,25 @@
- {
- m_length = 0;
- m_crc.Restart();
- +
- + m_filetime = 0;
- +
- + m_filename.erase(0);
- + m_filename.reserve(16);
- +
- + m_comment.erase(0);
- + m_comment.reserve(32);
- byte buf[6];
- byte b, flags;
- if (m_inQueue.Get(buf, 2)!=2) throw HeaderErr();
- if (buf[0] != MAGIC1 || buf[1] != MAGIC2) throw HeaderErr();
- - if (!m_inQueue.Skip(1)) throw HeaderErr(); // skip extra flags
- + if (!m_inQueue.Get(b) || (b != DEFLATED)) throw HeaderErr(); // skip CM flag
- if (!m_inQueue.Get(flags)) throw HeaderErr();
- if (flags & (ENCRYPTED | CONTINUED)) throw HeaderErr();
- - if (m_inQueue.Skip(6)!=6) throw HeaderErr(); // Skip file time, extra flags and OS type
- + if (m_inQueue.GetWord32(m_filetime, LITTLE_ENDIAN_ORDER) != 4) throw HeaderErr();
- + if (m_inQueue.Skip(2)!=2) throw HeaderErr(); // Skip extra flags and OS type
- if (flags & EXTRA_FIELDS) // skip extra fields
- {
- @@ -63,15 +84,25 @@
- if (m_inQueue.Skip(length)!=length) throw HeaderErr();
- }
- - if (flags & FILENAME) // skip filename
- + if (flags & FILENAME) // extract filename
- + {
- do
- + {
- if(!m_inQueue.Get(b)) throw HeaderErr();
- - while (b);
- + if(b) m_filename.append( 1, (char)b );
- + }
- + while (b);
- + }
- - if (flags & COMMENTS) // skip comments
- + if (flags & COMMENTS) // extract comments
- + {
- do
- + {
- if(!m_inQueue.Get(b)) throw HeaderErr();
- + if(b) m_comment.append( 1, (char)b );
- + }
- while (b);
- + }
- }
- void Gunzip::ProcessDecompressedData(const byte *inString, size_t length)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement