LibrePCB Developers Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ziparchive.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_ZIPARCHIVE_H
21#define LIBREPCB_CORE_ZIPARCHIVE_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "../utils/rusthandle.h"
27
28#include <QtCore>
29
30#include <optional>
31
32/*******************************************************************************
33 * Namespace / Forward Declarations
34 ******************************************************************************/
35namespace librepcb {
36
37class FilePath;
38
39namespace rs {
40struct ZipArchive;
41}
42
43/*******************************************************************************
44 * Class ZipArchive
45 ******************************************************************************/
46
52class ZipArchive final {
53public:
54 ZipArchive() = delete;
55 ZipArchive(const ZipArchive& other) = delete;
56 ZipArchive& operator=(const ZipArchive& rhs) = delete;
57
65 ZipArchive(const QByteArray& data);
66
74 ZipArchive(const FilePath& fp);
75
81 std::size_t getEntriesCount() const noexcept;
82
93 QString getFileName(std::size_t index);
94
104 QByteArray readFile(std::size_t index);
105
115 std::optional<QByteArray> tryReadFile(const QString& fileName);
116
125 void extractTo(const FilePath& dir);
126
127private:
129};
130
131/*******************************************************************************
132 * End of File
133 ******************************************************************************/
134
135} // namespace librepcb
136
137#endif
This class represents absolute, well-formatted paths to files or directories.
Definition filepath.h:127
Zip file reader.
Definition ziparchive.h:52
std::optional< QByteArray > tryReadFile(const QString &fileName)
Convenience method to find a file by name and read its content.
Definition ziparchive.cpp:91
QByteArray readFile(std::size_t index)
Read the content of a file.
Definition ziparchive.cpp:82
RustHandle< rs::ZipArchive > mHandle
Definition ziparchive.h:128
QString getFileName(std::size_t index)
Get the file name of an entry.
Definition ziparchive.cpp:72
ZipArchive & operator=(const ZipArchive &rhs)=delete
std::size_t getEntriesCount() const noexcept
Get number of ZIp entries (files & directories)
Definition ziparchive.cpp:68
void extractTo(const FilePath &dir)
Extract whole Zip to a directory (overwriting)
Definition ziparchive.cpp:100
ZipArchive(const ZipArchive &other)=delete
Definition occmodel.cpp:77
Definition uuid.h:186
Scoped pointer for Rust objects.
Definition rusthandle.h:41