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
10using namespace zipios ;
11
12using std::cerr ;
13using std::cout ;
14using std::endl ;
15using std::auto_ptr ;
16
17int 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*/
An FCollException is used to signal a problem with a FileCollection.
virtual ConstEntryPointer getEntry(const string &name, MatchPath matchpath=MATCH) const
Returns a ConstEntryPointer to a FileEntry object for the entry with the specified name.
Definition fcoll.cpp:34
virtual ConstEntries entries() const
Returns a vector of const pointers to the entries in the FileCollection.
Definition fcoll.cpp:17
virtual int size() const
Returns the number of entries in the FileCollection.
Definition fcoll.cpp:57
SimpleSmartPointer is a simple reference counting smart pointer template.
ZipFile is a FileCollection, where the files are stored in a .zip file.
Definition zipfile.h:20
static ZipFile openEmbeddedZipFile(const string &name)
Opens a Zip archive embedded in another file, by writing the zip archive to the end of the file follo...
Definition zipfile.cpp:19
virtual istream * getInputStream(const ConstEntryPointer &entry)
Returns a pointer to an opened istream for the specified FileEntry.
Definition zipfile.cpp:55
Header file that defines a number of exceptions used by FileCollection and its subclasses.
vector< EntryPointer > ConstEntries
ConstEntries is a vector of ConstEntryPointer's.
Definition fileentry.h:43
Header file that defines ZipFile.