Zipios++
test_appzip.cpp
Go to the documentation of this file.
1 
2 #include "zipios++/zipios-config.h"
3 
4 #include "zipios++/meta-iostreams.h"
5 #include <memory>
6 
8 #include "zipios++/zipfile.h"
9 
10 using namespace zipios ;
11 
12 using std::cerr ;
13 using std::cout ;
14 using std::endl ;
15 using std::auto_ptr ;
16 
17 int main( int , char *argv[] ) {
18  try {
19 
20  cout << "Instantiating a ZipFile" << endl ;
21  ZipFile zf = ZipFile::openEmbeddedZipFile( argv[ 0 ] ) ;
22 
23  cout << "list length : " << zf.size() << endl ;
24 
25  ConstEntries entries ;
26  entries = zf.entries() ;
27 
28 
29  ConstEntries::iterator it ;
30  for( it = entries.begin() ; it != entries.end() ; it++)
31  cout << *(*it) << endl ;
32 
33  ConstEntryPointer ent = zf.getEntry( "file2.txt", FileCollection::IGNORE ) ;
34  if ( ent != 0 ) {
35  auto_ptr< istream > is( zf.getInputStream( ent ) ) ;
36 
37  cout << "Contents of entry, " << ent->getName() << " :" << endl ;
38 
39  cout << is->rdbuf() ;
40  }
41  cout << "end of main()" << endl ;
42 
43  return 0 ;
44  }
45  catch( FCollException &excp ) {
46  cerr << "Exception caught in main() :" << endl ;
47  cerr << excp.what() << endl ;
48  cerr << "\nThe invalid virtual endings exception very probably means that\n"
49  << "this program hasn't had a zip file appended to it with 'appendzip'\n"
50  << "\nTry the following command and re-run " << argv[ 0 ] << " :\n"
51  << " ./appendzip " << argv[ 0 ] << " test.zip\n"
52  << endl ;
53  }
54  catch( exception &excp ) {
55  cerr << "Exception caught in main() :" << endl ;
56  cerr << excp.what() << endl ;
57  }
58  return -1;
59 }
60 
67 /*
68  Zipios++ - a small C++ library that provides easy access to .zip files.
69  Copyright (C) 2000 Thomas Søndergaard
70 
71  This library is free software; you can redistribute it and/or
72  modify it under the terms of the GNU Lesser General Public
73  License as published by the Free Software Foundation; either
74  version 2 of the License, or (at your option) any later version.
75 
76  This library is distributed in the hope that it will be useful,
77  but WITHOUT ANY WARRANTY; without even the implied warranty of
78  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
79  Lesser General Public License for more details.
80 
81  You should have received a copy of the GNU Lesser General Public
82  License along with this library; if not, write to the Free Software
83  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
84 */
Header file that defines ZipFile.
SimpleSmartPointer is a simple reference counting smart pointer template.
virtual ConstEntries entries() const
Definition: fcoll.cpp:17
virtual int size() const
Returns the number of entries in the FileCollection.
Definition: fcoll.cpp:57
An FCollException is used to signal a problem with a FileCollection.
virtual istream * getInputStream(const ConstEntryPointer &entry)
Definition: zipfile.cpp:55
Header file that defines a number of exceptions used by FileCollection and its subclasses.
static ZipFile openEmbeddedZipFile(const string &name)
Definition: zipfile.cpp:19
virtual ConstEntryPointer getEntry(const string &name, MatchPath matchpath=MATCH) const
Definition: fcoll.cpp:34