Mania++
 All Classes Functions Variables Pages
GZip.h
1 #ifndef GZIP_H_
2 #define GZIP_H_
3 
4 #include <sstream>
5 #include <boost/iostreams/filtering_streambuf.hpp>
6 #include <boost/iostreams/copy.hpp>
7 #include <boost/iostreams/filter/gzip.hpp>
8 
9 //* GZip
13 class GZip {
14 public:
20  static std::string Compress(const std::string& data)
21  {
22  namespace bio = boost::iostreams;
23 
24  std::stringstream compressed;
25  std::stringstream origin(data);
26 
27  bio::filtering_streambuf<bio::input> out;
28  out.push(bio::gzip_compressor(bio::gzip_params(bio::gzip::best_compression)));
29  out.push(origin);
30  bio::copy(out, compressed);
31 
32  return compressed.str();
33  }
34 
40  static std::string Decompress(const std::string& data)
41  {
42  namespace bio = boost::iostreams;
43 
44  std::stringstream compressed(data);
45  std::stringstream decompressed;
46 
47  bio::filtering_streambuf<bio::input> out;
48  out.push(bio::gzip_decompressor());
49  out.push(compressed);
50  bio::copy(out, decompressed);
51 
52  return decompressed.str();
53  }
54 };
55 
56 #endif // GZIP_H_
static std::string Decompress(const std::string &data)
Decompresses provided data.
Definition: GZip.h:40
Utility to gzip strings.
Definition: GZip.h:13
static std::string Compress(const std::string &data)
Compresses provided data.
Definition: GZip.h:20