Zipios++
test_zipoutputstream.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 
7 
8 using namespace zipios ;
9 
10 using std::cerr ;
11 using std::cout ;
12 using std::endl ;
13 using std::ifstream ;
14 using std::ios ;
15 using std::string ;
16 
17 void writeFileToZipOutputStream( ZipOutputStream &zos, const string &filename ) ;
18 
19 int main() {
20  try {
21 
22  ZipOutputStream ozs( "zos.zip" ) ;
23 
24  writeFileToZipOutputStream( ozs, "test_zip" ) ;
25  writeFileToZipOutputStream( ozs, "test_dircoll" ) ;
26  writeFileToZipOutputStream( ozs, "test.zip" ) ;
27  writeFileToZipOutputStream( ozs, "test_simplesmartptr" ) ;
28  writeFileToZipOutputStream( ozs, "test_appzip" ) ;
29 
30  cerr << "End of main" << endl ;
31 
32  return 0;
33  }
34  catch( exception &excp ) {
35  cerr << "Exception caught in main() :" << endl ;
36  cerr << excp.what() << endl ;
37  }
38  return -1;
39 }
40 
41 void writeFileToZipOutputStream( ZipOutputStream &zos, const string &filename ) {
42  zos.putNextEntry( ZipCDirEntry( filename ) ) ;
43 
44  ifstream ifs( filename.c_str(), ios::in | ios::binary ) ;
45 
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 ZipOutputStream.
Specialization of ZipLocalEntry, that add fields for storing the extra information, that is only present in the entries in the zip central directory and not in the local entry headers.
Definition: ziphead.h:102
void putNextEntry(const ZipCDirEntry &entry)