Zipios++
test_zipoutputstreambuf.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::ofstream ;
16 using std::string ;
17 
18 void writeFileToZipOutputStreambuf( ZipOutputStreambuf &zosb, const string &filename ) ;
19 
20 int main() {
21  try {
22  ofstream of( "zosb.zip", ios::out | ios::binary ) ;
23 
24  ZipOutputStreambuf ozf( of.rdbuf() ) ;
25 
26  writeFileToZipOutputStreambuf( ozf, "test_zip" ) ;
27  writeFileToZipOutputStreambuf( ozf, "test_dircoll" ) ;
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 writeFileToZipOutputStreambuf( ZipOutputStreambuf &zosb, const string &filename ) {
41  zosb.putNextEntry( ZipCDirEntry( filename ) ) ;
42 
43  ifstream ifs( filename.c_str(), ios::in | ios::binary ) ;
44  ostream ozs( &zosb ) ;
45  ozs << ifs.rdbuf() ;
46  cerr << ifs.rdbuf() ;
47 // char buf[ 100 ] ;
48 // int rds ;
49 // while ( ( rds = ifs.rdbuf()->sgetn( buf, 100 ) ) > 0 )
50 // ozs.write( buf, rds ) ;
51 
52  cerr << "ostream Stream state: " ;
53  cerr << "good() = " << ozs.good() << ",\t" ;
54  cerr << "fail() = " << ozs.fail() << ",\t" ;
55  cerr << "bad() = " << ozs.bad() << ",\t" ;
56  cerr << "eof() = " << ozs.eof() << endl << endl;
57 
58  cerr << "istream Stream state: " ;
59  cerr << "good() = " << ifs.good() << ",\t" ;
60  cerr << "fail() = " << ifs.fail() << ",\t" ;
61  cerr << "bad() = " << ifs.bad() << ",\t" ;
62  cerr << "eof() = " << ifs.eof() << endl << endl;
63 
64 }
65 
70 /*
71  Zipios++ - a small C++ library that provides easy access to .zip files.
72  Copyright (C) 2000 Thomas Søndergaard
73 
74  This library is free software; you can redistribute it and/or
75  modify it under the terms of the GNU Lesser General Public
76  License as published by the Free Software Foundation; either
77  version 2 of the License, or (at your option) any later version.
78 
79  This library is distributed in the hope that it will be useful,
80  but WITHOUT ANY WARRANTY; without even the implied warranty of
81  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
82  Lesser General Public License for more details.
83 
84  You should have received a copy of the GNU Lesser General Public
85  License along with this library; if not, write to the Free Software
86  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
87 */
Header file that defines ZipOutputStreambuf.
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
ZipOutputStreambuf is a zip output streambuf filter.
void putNextEntry(const ZipCDirEntry &entry)
Begins writing the next entry.