Debian Codegraph @

src/Base/ZipHeader.h

raw
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /***************************************************************************
4 * Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
5 * *
6 * This file is part of the FreeCAD CAx development system. *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Library General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Library General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Library General Public *
19 * License along with this library; see the file COPYING.LIB. If not, *
20 * write to the Free Software Foundation, Inc., 59 Temple Place, *
21 * Suite 330, Boston, MA 02111-1307, USA *
22 * *
23 ***************************************************************************/
24
25
26 #ifndef ZIPIOS_ZIP_HEADER_H
27 #define ZIPIOS_ZIP_HEADER_H
28
29 #include <FCGlobal.h>
30 #include <zipios++/ziphead.h>
31 #include <zipios++/virtualseeker.h>
32 #include <zipios++/fcoll.h>
33
34 namespace zipios
35 {
36
37 /** ZipHeader is a FileCollection, where the files are stored in a .zip file.
38 * The class is similar to zipios' ZipFile class with the difference that instead of
39 * a file a std::istream can be passed.
40 */
41 class BaseExport ZipHeader: public FileCollection
42 {
43 public:
44 /** Opens the zip file name. If the zip "file" is
45 embedded in a file that contains other data, e.g. a binary
46 program, the offset of the zip file start and end must be
47 specified.
48 @param inp The input stream of the zip file to open.
49 @param s_off Offset relative to the start of the file, that
50 indicates the beginning of the zip file.
51 @param e_off Offset relative to the end of the file, that
52 indicates the end of the zip file. The offset is a positive number,
53 even though the offset is towards the beginning of the file.
54 @throw FColException Thrown if the specified file name is not a valid zip
55 archive.
56 @throw IOException Thrown if an I/O problem is encountered, while the directory
57 of the specified zip archive is being read. */
58 explicit ZipHeader(std::istream& inp, int s_off = 0, int e_off = 0);
59
60 /** Create a copy of this instance. */
61 FileCollection* clone() const override;
62
63 void close() override;
64
65 std::istream* getInputStream(const ConstEntryPointer& entry) override;
66 std::istream* getInputStream(const string& entry_name, MatchPath matchpath = MATCH) override;
67
68 private:
69 std::istream& _input;
70 VirtualSeeker _vs;
71 EndOfCentralDirectory _eocd;
72
73 bool init(std::istream& _zipfile);
74 bool readCentralDirectory(std::istream& _zipfile);
75 bool readEndOfCentralDirectory(std::istream& _zipfile);
76 bool confirmLocalHeaders(std::istream& _zipfile);
77 void setError(std::string error_str);
78 };
79
80 } // namespace zipios
81
82
83 #endif // ZIPIOS_ZIP_HEADER_H