00001 #include "zipios++/zipios-config.h"
00002
00003 #include "zipios++/meta-iostreams.h"
00004 #include <string>
00005
00006 #include "zipios++/zipoutputstreambuf.h"
00007
00008 using namespace zipios ;
00009
00010 using std::ifstream ;
00011 using std::cout ;
00012 using std::cerr ;
00013 using std::endl ;
00014 using std::string ;
00015
00016 void writeFileToZipOutputStreambuf( ZipOutputStreambuf &zosb, const string &filename ) ;
00017
00018 int main() {
00019 try {
00020 ofstream of( "zosb.zip", ios::out | ios::binary ) ;
00021
00022 ZipOutputStreambuf ozf( of.rdbuf() ) ;
00023
00024 writeFileToZipOutputStreambuf( ozf, "test_zip" ) ;
00025 writeFileToZipOutputStreambuf( ozf, "test_dircoll" ) ;
00026
00027 cerr << "End of main" << endl ;
00028
00029 return 0;
00030 }
00031 catch( exception &excp ) {
00032 cerr << "Exception caught in main() :" << endl ;
00033 cerr << excp.what() << endl ;
00034 }
00035 }
00036
00037 void writeFileToZipOutputStreambuf( ZipOutputStreambuf &zosb, const string &filename ) {
00038 zosb.putNextEntry( ZipCDirEntry( filename ) ) ;
00039
00040 ifstream ifs( filename.c_str(), ios::in | ios::binary ) ;
00041 ostream ozs( &zosb ) ;
00042 ozs << ifs.rdbuf() ;
00043 cerr << ifs.rdbuf() ;
00044
00045
00046
00047
00048
00049 cerr << "ostream Stream state: " ;
00050 cerr << "good() = " << ozs.good() << ",\t" ;
00051 cerr << "fail() = " << ozs.fail() << ",\t" ;
00052 cerr << "bad() = " << ozs.bad() << ",\t" ;
00053 cerr << "eof() = " << ozs.eof() << endl << endl;
00054
00055 cerr << "istream Stream state: " ;
00056 cerr << "good() = " << ifs.good() << ",\t" ;
00057 cerr << "fail() = " << ifs.fail() << ",\t" ;
00058 cerr << "bad() = " << ifs.bad() << ",\t" ;
00059 cerr << "eof() = " << ifs.eof() << endl << endl;
00060
00061 }
00062
00067 00068 00069 00070 00071 00072 00073 00074 00075 00076 00077 00078 00079 00080 00081 00082 00083 00084