/* */ #ifndef D_GZIP_ENCODER_H #define D_GZIP_ENCODER_H #include "common.h" #include #include namespace aria2 { class GZipEncoder { private: z_stream* strm_; bool finished_; // Internal buffer for deflated data. std::string internalBuf_; std::string encode(const unsigned char* in, size_t length, int flush); // Not implemented GZipEncoder& operator<<(char c); public: GZipEncoder(); ~GZipEncoder(); // Initializes deflator. void init(); // Feeds NULL-terminated c-string s to deflater. The deflated // result is kept in this class. GZipEncoder& operator<<(const char* s); // Feeds binary data in s to deflater. The deflated result is kept // in this class. GZipEncoder& operator<<(const std::string& s); // Feeds binary data in s with size length to deflater. The // deflated result is kept in this class. GZipEncoder& write(const char* s, size_t length); // Feeds integer to deflator. Before passed to deflator, i is // converted to std::string using util::itos(). The deflated result // is kept in this class. GZipEncoder& operator<<(int64_t i); // Feeds binary data pointed by in with size length to deflator and // returns compressed output available so far. Don't use this // method with operator<< methods. std::string encode(const unsigned char* in, size_t length) { return encode(in, length, Z_NO_FLUSH); } // Releases allocated resources. void release(); // Returns deflated result kept internally. After this function // call, further calls to operator<<() and encode() are not allowed. std::string str(); }; } // namespace aria2 #endif // D_GZIP_ENCODER_H