| 1 | #include <cstdlib>
|
|---|
| 2 | #include <fstream>
|
|---|
| 3 | #include <iostream>
|
|---|
| 4 |
|
|---|
| 5 | #include <boost/iostreams/filtering_stream.hpp>
|
|---|
| 6 | #include <boost/iostreams/filter/gzip.hpp>
|
|---|
| 7 |
|
|---|
| 8 | struct exited
|
|---|
| 9 | {
|
|---|
| 10 | ~exited() {
|
|---|
| 11 | std::cout << "dtors finished";
|
|---|
| 12 | }
|
|---|
| 13 | };
|
|---|
| 14 |
|
|---|
| 15 | int main(int argc, char** argv)
|
|---|
| 16 | {
|
|---|
| 17 | exited x;
|
|---|
| 18 | if (argc < 3) {
|
|---|
| 19 | std::cout << "Usage: " << argv[0] << " file bytes\n";
|
|---|
| 20 | return 1;
|
|---|
| 21 | }
|
|---|
| 22 | std::ofstream ofs(argv[1], std::ios_base::binary);
|
|---|
| 23 | boost::iostreams::filtering_stream<boost::iostreams::output> filter;
|
|---|
| 24 | filter.push(boost::iostreams::gzip_compressor(boost::iostreams::gzip_params()));
|
|---|
| 25 | filter.push(ofs);
|
|---|
| 26 | int bytes = atoi(argv[2]);
|
|---|
| 27 | char *data = new char[bytes];
|
|---|
| 28 | srand(0); //fill with random data that won't get gzipped to a few bytes
|
|---|
| 29 | for (int i = 0; i < bytes - 1; ++i) {
|
|---|
| 30 | data[i] = rand() % 254 + 1;
|
|---|
| 31 | }
|
|---|
| 32 | data[bytes - 1] = 0;
|
|---|
| 33 | filter << data;
|
|---|
| 34 | delete[] data;
|
|---|
| 35 | std::cout << "main ended ";
|
|---|
| 36 | }
|
|---|