Zipios++
test_gzipoutputstream.cpp
Go to the documentation of this file.
1 #include "zipios++/zipios-config.h"
2 
3 #include "zipios++/meta-iostreams.h"
4 #include <string>
5 #include <exception>
6 
8 
9 using namespace zipios ;
10 
11 using std::cerr ;
12 using std::cout ;
13 using std::endl ;
14 using std::ifstream ;
15 using std::ofstream ;
16 using std::ios ;
17 using std::string ;
18 using std::exception ;
19 
20 void writeFileToGZIPOutputStream( GZIPOutputStream &zos, const string &filename ) ;
21 
22 int main() {
23  try {
24 
25  GZIPOutputStream ozs("zos.gz") ;
26 
27  writeFileToGZIPOutputStream( ozs, "test.xml" ) ;
28 
29  cerr << "End of main" << endl ;
30 
31  return 0;
32  }
33  catch( exception &excp ) {
34  cerr << "Exception caught in main() :" << endl ;
35  cerr << excp.what() << endl ;
36  }
37  return -1;
38 }
39 
40 void writeFileToGZIPOutputStream( GZIPOutputStream &zos, const string &filename ) {
41 
42  ifstream ifs( filename.c_str(), ios::in | ios::binary ) ;
43 
44  zos.setFilename(filename);
45  zos.setComment("ZIPIOS++ TestFile");
46  zos << ifs.rdbuf() ;
47 
48  cerr << "ostream Stream state: " ;
49  cerr << "good() = " << zos.good() << ",\t" ;
50  cerr << "fail() = " << zos.fail() << ",\t" ;
51  cerr << "bad() = " << zos.bad() << ",\t" ;
52  cerr << "eof() = " << zos.eof() << endl ;
53 
54  cerr << "istream Stream state: " ;
55  cerr << "good() = " << ifs.good() << ",\t" ;
56  cerr << "fail() = " << ifs.fail() << ",\t" ;
57  cerr << "bad() = " << ifs.bad() << ",\t" ;
58  cerr << "eof() = " << ifs.eof() << endl ;
59 
60 }
61 
66 /*
67  Zipios++ - a small C++ library that provides easy access to .zip files.
68  Copyright (C) 2000 Thomas Søndergaard
69 
70  This library is free software; you can redistribute it and/or
71  modify it under the terms of the GNU Lesser General Public
72  License as published by the Free Software Foundation; either
73  version 2 of the License, or (at your option) any later version.
74 
75  This library is distributed in the hope that it will be useful,
76  but WITHOUT ANY WARRANTY; without even the implied warranty of
77  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
78  Lesser General Public License for more details.
79 
80  You should have received a copy of the GNU Lesser General Public
81  License along with this library; if not, write to the Free Software
82  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
83 */
Header file that defines GZIPOutputStream.