| 1 | #include <boost/iostreams/filter/gzip.hpp>
 | 
|---|
| 2 | #include <boost/iostreams/filtering_stream.hpp>
 | 
|---|
| 3 | 
 | 
|---|
| 4 | #include <cstdlib>
 | 
|---|
| 5 | #include <fstream>
 | 
|---|
| 6 | #include <iostream>
 | 
|---|
| 7 | #include <string>
 | 
|---|
| 8 | 
 | 
|---|
| 9 | using namespace std;
 | 
|---|
| 10 | using namespace boost::iostreams;
 | 
|---|
| 11 | 
 | 
|---|
| 12 | int main(int argc, char** argv) {
 | 
|---|
| 13 |     if (argc != 2) {
 | 
|---|
| 14 |         cerr << "specify a file to decompress.\n";
 | 
|---|
| 15 |         exit(1);
 | 
|---|
| 16 |     }
 | 
|---|
| 17 | 
 | 
|---|
| 18 |     ifstream f(argv[1]);
 | 
|---|
| 19 |     if (!f) {
 | 
|---|
| 20 |         cerr << "failed to open " << argv[1] << "\n";
 | 
|---|
| 21 |         exit(1);
 | 
|---|
| 22 |     }
 | 
|---|
| 23 | 
 | 
|---|
| 24 |     filtering_stream<input> s;
 | 
|---|
| 25 |     gzip_decompressor gz;
 | 
|---|
| 26 |     s.push(gz);
 | 
|---|
| 27 |     s.push(f);
 | 
|---|
| 28 |     string line;
 | 
|---|
| 29 |     unsigned count = 0;
 | 
|---|
| 30 |     while (getline(s, line) && ++count)
 | 
|---|
| 31 |         cout << line << "\n";
 | 
|---|
| 32 |     cout << "read " << count << " lines\n";
 | 
|---|
| 33 | 
 | 
|---|
| 34 |     return 0;
 | 
|---|
| 35 | }
 | 
|---|