1/* This file is part of the KDE libraries
2 SPDX-FileCopyrightText: 2011 Mario Bensi <mbensi@ipsquad.net>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6#ifndef K7ZIP_H
7#define K7ZIP_H
8
9#include <karchive.h>
10
11/**
12 * @class K7Zip k7zip.h K7Zip
13 *
14 * A class for reading / writing p7zip archives.
15 *
16 * @author Mario Bensi
17 */
18class KARCHIVE_EXPORT K7Zip : public KArchive
19{
20 Q_DECLARE_TR_FUNCTIONS(K7Zip)
21
22public:
23 /**
24 * Creates an instance that operates on the given filename
25 * using the compression filter associated to given mimetype.
26 *
27 * @param filename is a local path (e.g. "/home/user/myfile.7z")
28 */
29 explicit K7Zip(const QString &filename);
30
31 /**
32 * Creates an instance that operates on the given device.
33 * The device can be compressed (KCompressionDevice) or not (QFile, etc.).
34 * @warning Do not assume that giving a QFile here will decompress the file,
35 * in case it's compressed!
36 * @param dev the device to read from. If the source is compressed, the
37 * QIODevice must take care of decompression
38 */
39 explicit K7Zip(QIODevice *dev);
40
41 /**
42 * If the archive is still opened, then it will be
43 * closed automatically by the destructor.
44 */
45 ~K7Zip() override;
46
47protected:
48 /// Reimplemented from KArchive
49 bool doWriteSymLink(const QString &name,
50 const QString &target,
51 const QString &user,
52 const QString &group,
53 mode_t perm,
54 const QDateTime &atime,
55 const QDateTime &mtime,
56 const QDateTime &ctime) override;
57 /// Reimplemented from KArchive
58 bool doWriteDir(const QString &name,
59 const QString &user,
60 const QString &group,
61 mode_t perm,
62 const QDateTime &atime,
63 const QDateTime &mtime,
64 const QDateTime &ctime) override;
65 /// Reimplemented from KArchive
66 bool doPrepareWriting(const QString &name,
67 const QString &user,
68 const QString &group,
69 qint64 size,
70 mode_t perm,
71 const QDateTime &atime,
72 const QDateTime &mtime,
73 const QDateTime &ctime) override;
74 /// Reimplemented from KArchive
75 bool doFinishWriting(qint64 size) override;
76
77 /// Reimplemented from KArchive
78 bool doWriteData(const char *data, qint64 size) override;
79
80 /**
81 * Opens the archive for reading.
82 * Parses the directory listing of the archive
83 * and creates the KArchiveDirectory/KArchiveFile entries.
84 * @param mode the mode of the file
85 */
86 bool openArchive(QIODevice::OpenMode mode) override;
87 bool closeArchive() override;
88
89protected:
90 void virtual_hook(int id, void *data) override;
91
92private:
93 class K7ZipPrivate;
94 K7ZipPrivate *const d;
95};
96
97#endif
98

source code of karchive/src/k7zip.h