1 /*****************************************************************************
2 * PokerTH - The open source texas holdem engine *
3 * Copyright (C) 2006-2012 Felix Hammer, Florian Thauer, Lothar May *
4 * *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU Affero General Public License as *
7 * published by the Free Software Foundation, either version 3 of the *
8 * License, or (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU Affero General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Affero General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17 * *
18 * *
19 * Additional permission under GNU AGPL version 3 section 7 *
20 * *
21 * If you modify this program, or any covered work, by linking or *
22 * combining it with the OpenSSL project's OpenSSL library (or a *
23 * modified version of that library), containing parts covered by the *
24 * terms of the OpenSSL or SSLeay licenses, the authors of PokerTH *
25 * (Felix Hammer, Florian Thauer, Lothar May) grant you additional *
26 * permission to convey the resulting work. *
27 * Corresponding Source for a non-source form of such a combination *
28 * shall include the source code for the parts of OpenSSL used as well *
29 * as that of the covered work. *
30 *****************************************************************************/
31
32 #include <boost/filesystem.hpp>
33 #include <boost/iostreams/filtering_streambuf.hpp>
34 #include <boost/iostreams/copy.hpp>
35 #include <boost/iostreams/filter/zlib.hpp>
36 #include <iostream>
37 #include <fstream>
38 #include <string>
39
40
41 using namespace std;
42 using namespace boost::filesystem;
43
44
45 int
main(int argc,char * argv[])46 main(int argc, char *argv[])
47 {
48 if (argc != 2) {
49 cout << "Usage: zlib_compress <text input file>" << endl;
50 return 1;
51 }
52 // Use input file name, and write to input file with additional ".z".
53 path inputFilePath(argv[1]);
54 path outputFilePath(inputFilePath);
55 outputFilePath = change_extension(outputFilePath, extension(outputFilePath) + ".z");
56 // Check whether file exists.
57 if (!exists(inputFilePath)) {
58 cerr << "Input file does not exist." << endl;
59 return 2;
60 }
61 try {
62 std::ifstream inFile(inputFilePath.directory_string().c_str(), ios_base::in);
63 std::ofstream outFile(outputFilePath.directory_string().c_str(), ios_base::out | ios_base::binary);
64 boost::iostreams::filtering_streambuf<boost::iostreams::output> out;
65 out.push(boost::iostreams::zlib_compressor());
66 out.push(outFile);
67 boost::iostreams::copy(inFile, out);
68 cout << "Compression of \"" << inputFilePath.directory_string() << "\" to \"" << outputFilePath.directory_string() << "\" was successful." << endl;
69 } catch (...) {
70 cerr << "Compression failed." << endl;
71 return 3;
72 }
73
74 return 0;
75 }
76
77