Main Page   Class Hierarchy   Compound List   File List   Compound Members  

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

Generated at Tue Aug 14 20:39:26 2001 for Zipios++ by doxygen1.2.0 written by Dimitri van Heesch, © 1997-2000