Zipios++

test_zipoutputstreambuf.cpp

Go to the documentation of this file.
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 //    char buf[ 100 ] ;
00048 //    int rds ;
00049 //    while ( ( rds = ifs.rdbuf()->sgetn( buf, 100 ) ) > 0 ) 
00050 //      ozs.write( buf, rds ) ;
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   Zipios++ - a small C++ library that provides easy access to .zip files.
00072   Copyright (C) 2000  Thomas Søndergaard
00073   
00074   This library is free software; you can redistribute it and/or
00075   modify it under the terms of the GNU Lesser General Public
00076   License as published by the Free Software Foundation; either
00077   version 2 of the License, or (at your option) any later version.
00078   
00079   This library is distributed in the hope that it will be useful,
00080   but WITHOUT ANY WARRANTY; without even the implied warranty of
00081   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00082   Lesser General Public License for more details.
00083   
00084   You should have received a copy of the GNU Lesser General Public
00085   License along with this library; if not, write to the Free Software
00086   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00087 */