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::cerr ;
00011 using std::cout ;
00012 using std::endl ;
00013 using std::ifstream ;
00014 using std::ios ;
00015 using std::ofstream ;
00016 using std::string ;
00017
00018 void writeFileToZipOutputStreambuf( ZipOutputStreambuf &zosb, const string &filename ) ;
00019
00020 int main() {
00021 try {
00022 ofstream of( "zosb.zip", ios::out | ios::binary ) ;
00023
00024 ZipOutputStreambuf ozf( of.rdbuf() ) ;
00025
00026 writeFileToZipOutputStreambuf( ozf, "test_zip" ) ;
00027 writeFileToZipOutputStreambuf( ozf, "test_dircoll" ) ;
00028
00029 cerr << "End of main" << endl ;
00030
00031 return 0;
00032 }
00033 catch( exception &excp ) {
00034 cerr << "Exception caught in main() :" << endl ;
00035 cerr << excp.what() << endl ;
00036 }
00037 return -1;
00038 }
00039
00040 void writeFileToZipOutputStreambuf( ZipOutputStreambuf &zosb, const string &filename ) {
00041 zosb.putNextEntry( ZipCDirEntry( filename ) ) ;
00042
00043 ifstream ifs( filename.c_str(), ios::in | ios::binary ) ;
00044 ostream ozs( &zosb ) ;
00045 ozs << ifs.rdbuf() ;
00046 cerr << ifs.rdbuf() ;
00047
00048
00049
00050
00051
00052 cerr << "ostream Stream state: " ;
00053 cerr << "good() = " << ozs.good() << ",\t" ;
00054 cerr << "fail() = " << ozs.fail() << ",\t" ;
00055 cerr << "bad() = " << ozs.bad() << ",\t" ;
00056 cerr << "eof() = " << ozs.eof() << endl << endl;
00057
00058 cerr << "istream Stream state: " ;
00059 cerr << "good() = " << ifs.good() << ",\t" ;
00060 cerr << "fail() = " << ifs.fail() << ",\t" ;
00061 cerr << "bad() = " << ifs.bad() << ",\t" ;
00062 cerr << "eof() = " << ifs.eof() << endl << endl;
00063
00064 }
00065
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087