summaryrefslogtreecommitdiff
path: root/c,cc/compression_test.cc
blob: 21bfafc1e17f1350697074c4d7bdd3283ed965fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <iostream>
#include <fstream>
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filter/zlib.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_stream.hpp>

using namespace boost::iostreams;
using namespace std;


int main(void)
{
  //ofstream raw("out-raw");
  filtering_ostream out_z;
  out_z.push(gzip_compressor());
  //out_gz.push(gzip_compressor());
  out_z.push(file_sink("out-z", std::ios::binary));
  //out_gz.push(file_sink("out-gz", std::ios::binary));
  for (size_t i = 0; i < 10; i++) {
    out_z << "line #" << i << endl;
    //out_gz << "line #" << i << endl;
    //out_bz << "line #" << i << endl;
    //raw << "line #" << i << endl;
  }
  //    flush(out);
  close(out_z);
  //close(out_gz);
  //close(out_bz);
  //raw.close();

  for (size_t i = 0; i < 5; i++) {
    ifstream file("out-z", ios_base::in | ios_base::binary);
    filtering_istream in;
    in.push(gzip_decompressor());
    in.push(file);
    string s;
    while (getline(in, s)) {
      cout << s << endl;
    }
    file.close();
  }
}