Debian Codegraph @

src/tools/zip/zip.h

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2
3 /* libmwaw: tools
4 * Version: MPL 2.0 / LGPLv2+
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 2.0 (the "License"); you may not use this file except in compliance with
8 * the License or as specified alternatively below. You may obtain a copy of
9 * the License at http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * Major Contributor(s):
17 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
18 *
19 *
20 * All Rights Reserved.
21 *
22 * For minor contributions see the git repository.
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
26 * in which case the provisions of the LGPLv2+ are applicable
27 * instead of those above.
28 */
29
30 #ifndef MWAW_ZIP_H
31 # define MWAW_ZIP_H
32
33 #include <zlib.h>
34
35 #include <fstream>
36 #include <map>
37 #include <string>
38 #include <vector>
39
40 #include "zip_internal.h"
41
42 class InputStream;
43
44 namespace libmwaw_zip
45 {
46 //! interface to zlib.h
47 class Zip
48 {
49 public:
50 //! constructor
51 Zip();
52 //! destructor
53 ~Zip();
54
55 /** try open filename ( to write data ) */
56 bool open(char const *filename);
57 /** returns true if the output is opened */
58 bool isOpened() const
59 {
60 return bool(m_output);
61 }
62 /** try to close the actual output */
63 bool close();
64 /** try add to a new file */
65 bool add(std::shared_ptr<InputStream> stream, char const *base, char const *path=0);
66
67 protected:
68 struct Directory;
69 struct File;
70 //! the output
71 std::ofstream m_output;
72 //! a map path->directory
73 std::map<std::string, Directory> m_nameDirectoryMap;
74
75 //! small structure used to store a file data
76 struct File {
77 //! constructor
78 File(std::string const &base, std::string const &dir);
79
80 //! try to write the input data in output
81 bool write(std::shared_ptr<InputStream> input, std::ostream &output);
82 //! try to write the central information in output
83 bool writeCentralInformation(std::ostream &output) const;
84 protected:
85 //! the basename
86 std::string m_base;
87 //! the directory
88 std::string m_dir;
89 //! the uncompressed length
90 uInt m_uncompressedLength;
91 //! the compressed length
92 uInt m_compressedLength;
93 //! true if we called deflate on the data
94 bool m_deflate;
95 //! the crc
96 uLong m_crc32;
97 //! the offset in file of the local file header
98 uLong m_offsetInFile;
99 };
100 //! small structure used to store a directory and its file
101 struct Directory {
102 //! constructor
103 explicit Directory(std::string const &dir);
104 //! try to add a file checking if a file with the same name already exist
105 bool add(std::shared_ptr<InputStream> input, char const *base, std::ostream &output);
106 /** try to write the central information in output
107
108 \note returns the number of central information written */
109 int writeCentralInformation(std::ostream &output) const;
110 //! the directory
111 std::string m_dir;
112 //! a map of filename -> file
113 std::map<std::string, File> m_nameFileMap;
114 };
115 };
116 }
117
118 #endif
119 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: