zipios++  2.0.2
Zipios++ – a small C++ library that provides easy access to .zip files.
zipios_example.cpp
Go to the documentation of this file.
1 /*
2  Zipios++ - a small C++ library that provides easy access to .zip files.
3 
4  Copyright (C) 2000-2007 Thomas Sondergaard
5  Copyright (C) 2015 Made to Order Software Corporation
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21 
32 #include "zipios++/zipfile.hpp"
33 
34 
35 int main(int argc, char *argv[])
36 {
37  if(argc != 3)
38  {
39  std::cerr << "error: usage: zipios_example <path to test.zip> <filename to extract and print>" << std::endl;
40  std::cerr << " from the source directory, try as:" << std::endl;
41  std::cerr << " zipios_example tests/test.zip test2.txt" << std::endl;
42  return 1;
43  }
44 
45  try
46  {
47  std::cout << "Instantiating a ZipFile" << std::endl;
48  zipios::ZipFile zf(argv[1]);
49 
50  std::cout << "list length: " << zf.size() << std::endl;
51 
53  for(auto it = entries.begin(); it != entries.end(); ++it)
54  {
55  std::cout << " " << *(*it) << std::endl;
56  }
57 
59  if(ent)
60  {
62  if(is)
63  {
64  std::cout << "Contents of entry, " << ent->getName() << ":" << std::endl;
65 
66  std::cout << is->rdbuf();
67  }
68  else
69  {
70  std::cerr << "error: found an entry for " << ent->getName() << " in test.zip, but could not read it with getInputStream()" << std::endl;
71  }
72  }
73  else
74  {
75  std::cerr << "error: could not read " << ent->getName() << " from test.zip" << std::endl;
76  }
77 
78  std::cout << "end of main()" << std::endl;
79  }
80  catch(std::exception const& e)
81  {
82  std::cerr << "Exception caught in main() :" << std::endl;
83  std::cerr << e.what() << std::endl;
84  return 1;
85  }
86 
87  return 0;
88 }
89 
90 // Local Variables:
91 // mode: cpp
92 // indent-tabs-mode: nil
93 // c-basic-offset: 4
94 // tab-width: 4
95 // End:
96 
97 // vim: ts=4 sw=4 et
The ZipFile class represents a collection of files.
Definition: zipfile.hpp:47
virtual FileEntry::pointer_t getEntry(std::string const &name, MatchPath matchpath=MatchPath::MATCH) const
Get an entry from this collection.
int main(int argc, char *argv[])
std::shared_ptr< std::istream > stream_pointer_t
A shared pointer to an input stream.
virtual FileEntry::vector_t entries() const
Retrieve the array of entries.
virtual size_t size() const
Returns the number of entries in the FileCollection.
Define the zipios::ZipFile class.
virtual stream_pointer_t getInputStream(std::string const &entry_name, MatchPath matchpath=MatchPath::MATCH) override
Retrieve a pointer to a file in the Zip archive.
Definition: zipfile.cpp:448
std::shared_ptr< FileEntry > pointer_t
Definition: fileentry.hpp:77
std::vector< pointer_t > vector_t
Definition: fileentry.hpp:78