zipios
2.2.0
Zipios – a small C++ library that provides easy access to .zip files.
tools
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-2019 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.1 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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
52
zipios::FileEntry::vector_t
entries(zf.
entries
());
53
for
(
auto
it = entries.begin(); it != entries.end(); ++it)
54
{
55
std::cout <<
" "
<< *(*it) << std::endl;
56
}
57
58
zipios::FileEntry::pointer_t
ent(zf.
getEntry
(argv[2],
zipios::FileCollection::MatchPath::IGNORE
));
59
if
(ent)
60
{
61
zipios::ZipFile::stream_pointer_t
is(zf.
getInputStream
(ent->getName()));
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
zipios::FileCollection::entries
virtual FileEntry::vector_t entries() const
Retrieve the array of entries.
Definition:
filecollection.cpp:396
zipios::FileCollection::getEntry
virtual FileEntry::pointer_t getEntry(std::string const &name, MatchPath matchpath=MatchPath::MATCH) const
Get an entry from this collection.
Definition:
filecollection.cpp:424
zipios::FileCollection::stream_pointer_t
std::shared_ptr< std::istream > stream_pointer_t
A shared pointer to an input stream.
Definition:
filecollection.hpp:45
zipios::FileCollection::size
virtual size_t size() const
Returns the number of entries in the FileCollection.
Definition:
filecollection.cpp:474
zipfile.hpp
Define the zipios::ZipFile class.
zipios::FileEntry::pointer_t
std::shared_ptr< FileEntry > pointer_t
Definition:
fileentry.hpp:78
main
int main(int argc, char *argv[])
Definition:
zipios_example.cpp:35
zipios::FileCollection::MatchPath::IGNORE
@ IGNORE
zipios::ZipFile
The ZipFile class represents a collection of files.
Definition:
zipfile.hpp:47
zipios::ZipFile::getInputStream
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:496
zipios::FileEntry::vector_t
std::vector< pointer_t > vector_t
Definition:
fileentry.hpp:79
Generated on Fri Jan 31 2020 00:00:00 for zipios by
1.8.17