Line data Source code
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 :
22 : /** \file
23 : * \brief Implementation of zipios::ZipInputStream.
24 : *
25 : * This file includes the implementation of the zipios::ZipInputStream
26 : * class which is a filter used to read files from Zip archives, files
27 : * that can be compressed using the zlib library.
28 : */
29 :
30 : #include "zipinputstream.hpp"
31 :
32 : #include <fstream>
33 :
34 :
35 : namespace zipios
36 : {
37 :
38 :
39 : /** \class ZipInputStream
40 : * \brief The ZipInputStream to read data from a Zip archive.
41 : *
42 : * ZipInputStream is an istream that gets its input from a zip file. The
43 : * interface was redesigned in version 2.x to be more C++ like.
44 : *
45 : * \note
46 : * The getNextEntry() was removed because we cannot make it work here.
47 : * The old implementation would let someone read all the local directory
48 : * entries one after another. Only that is not correct and since this class
49 : * is not publicly exposed anymore, it wouldn't be available anyway.
50 : */
51 :
52 :
53 : /** \brief Initialize a ZipInputStream from a filename and position.
54 : *
55 : * This constructor creates a ZIP file stream by attaching itself to
56 : * a file as defined by the specified filename and a position to the
57 : * header of the file being read.
58 : *
59 : * \param[in] filename The name of a valid zip file.
60 : * \param[in] pos position to reposition the istream to before reading.
61 : */
62 96763 : ZipInputStream::ZipInputStream(std::string const& filename, std::streampos pos)
63 : : std::istream(nullptr)
64 96763 : , m_ifs(new std::ifstream(filename, std::ios::in | std::ios::binary))
65 193546 : , m_izf(new ZipInputStreambuf(m_ifs->rdbuf(), pos))
66 : {
67 : // properly initialize the stream with the newly allocated buffer
68 96743 : init(m_izf.get());
69 96743 : }
70 :
71 :
72 : /** \brief Clean up the input stream.
73 : *
74 : * The destructor ensures that all resources used by the class get
75 : * released.
76 : */
77 193486 : ZipInputStream::~ZipInputStream()
78 : {
79 193486 : }
80 :
81 :
82 3 : } // zipios namespace
83 :
84 : // Local Variables:
85 : // mode: cpp
86 : // indent-tabs-mode: nil
87 : // c-basic-offset: 4
88 : // tab-width: 4
89 : // End:
90 :
91 : // vim: ts=4 sw=4 et
|