summaryrefslogtreecommitdiff
path: root/gzip.h
diff options
context:
space:
mode:
authorc0ff <dsbaikov@gmail.com>2017-05-12 22:09:21 +0300
committerJeffrey Walton <noloader@gmail.com>2017-05-12 15:09:21 -0400
commitd901ecd9a4debb625f0f7f24c0dc4178feb8c679 (patch)
tree91f08c0055a95b4a8fd423f8e8f69bc6acad000e /gzip.h
parent973de7712a63a7a08ffda24da3043e7f37f7f9aa (diff)
downloadcryptopp-git-d901ecd9a4debb625f0f7f24c0dc4178feb8c679.tar.gz
Gunzip: added GetFilename() and GetComment() methods (#418)
Add Filename, Filtetime and Comment support to Gzip classes
Diffstat (limited to 'gzip.h')
-rw-r--r--gzip.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/gzip.h b/gzip.h
index a53a23e4..3f7b7cdc 100644
--- a/gzip.h
+++ b/gzip.h
@@ -35,9 +35,29 @@ public:
Gzip(const NameValuePairs &parameters, BufferedTransformation *attachment=NULLPTR)
: Deflator(parameters, attachment), m_totalLen(0) {}
+ //! \param filetime the filetime to set in the header. The application is responsible for setting it.
+ void SetFiletime(word32 filetime) { m_filetime = filetime; }
+
+ //! \param filename the original filename to set in the header. The application is responsible for setting it.
+ //! RFC 1952 requires a ISO/IEC 8859-1 encoding.
+ //! \param throwOnEncodingError if throwOnEncodingError is true, then the filename is checked to ensure it is
+ //! ISO/IEC 8859-1 encoded. If the filename does not adhere to ISO/IEC 8859-1, then a InvalidDataFormat
+ //! is thrown. If throwOnEncodingError is false then the filename is not checked.
+ void SetFilename(const std::string& filename, bool throwOnEncodingError = false);
+
+ //! \param comment the comment to set in the header. The application is responsible for setting it.
+ //! RFC 1952 requires a ISO/IEC 8859-1 encoding.
+ //! \param throwOnEncodingError if throwOnEncodingError is true, then the comment is checked to ensure it is
+ //! ISO/IEC 8859-1 encoded. If the comment does not adhere to ISO/IEC 8859-1, then a InvalidDataFormat
+ //! is thrown. If throwOnEncodingError is false then the comment is not checked.
+ void SetComment(const std::string& comment, bool throwOnEncodingError = false);
+
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);
@@ -45,6 +65,10 @@ protected:
word32 m_totalLen;
CRC32 m_crc;
+
+ word32 m_filetime;
+ std::string m_filename;
+ std::string m_comment;
};
//! \class Gunzip
@@ -73,6 +97,21 @@ public:
//! \param autoSignalPropagation 0 to turn off MessageEnd signal
Gunzip(BufferedTransformation *attachment = NULLPTR, bool repeat = false, int autoSignalPropagation = -1);
+ //! \return the filetime of the stream as set in the header. The application is responsible for setting it on the decompressed file.
+ word32 GetFiletime() const { return m_filetime; }
+
+ //! \return the filename of the stream as set in the header. The application is responsible for setting it on the decompressed file.
+ //! \param throwOnEncodingError if throwOnEncodingError is true, then the filename is checked to ensure it is
+ //! ISO/IEC 8859-1 encoded. If the filename does not adhere to ISO/IEC 8859-1, then a InvalidDataFormat is thrown.
+ //! If throwOnEncodingError is false then the filename is not checked.
+ const std::string& GetFilename(bool throwOnEncodingError = false) const;
+
+ //! \return the comment of the stream as set in the header.
+ //! \param throwOnEncodingError if throwOnEncodingError is true, then the comment is checked to ensure it is
+ //! ISO/IEC 8859-1 encoded. If the comment does not adhere to ISO/IEC 8859-1, then a InvalidDataFormat is thrown.
+ //! If throwOnEncodingError is false then the comment is not checked.
+ const std::string& GetComment(bool throwOnEncodingError = false) const;
+
protected:
enum {
//! \brief First header magic value
@@ -94,6 +133,10 @@ protected:
word32 m_length;
CRC32 m_crc;
+
+ word32 m_filetime;
+ std::string m_filename;
+ std::string m_comment;
};
NAMESPACE_END