1 | /* This file is part of the KDE libraries |
2 | SPDX-FileCopyrightText: 2000-2005 David Faure <faure@kde.org> |
3 | SPDX-FileCopyrightText: 2003 Leo Savernik <l.savernik@aon.at> |
4 | |
5 | SPDX-License-Identifier: LGPL-2.0-or-later |
6 | */ |
7 | #ifndef KTAR_H |
8 | #define KTAR_H |
9 | |
10 | #include <karchive.h> |
11 | |
12 | /*! |
13 | * \class KTar |
14 | * \inmodule KArchive |
15 | * |
16 | * \brief A class for reading / writing (optionally compressed) tar archives. |
17 | * |
18 | * KTar allows you to read and write tar archives, including those |
19 | * that are compressed using gzip, bzip2, xz or lzip. |
20 | */ |
21 | class KARCHIVE_EXPORT KTar : public KArchive |
22 | { |
23 | Q_DECLARE_TR_FUNCTIONS(KTar) |
24 | |
25 | public: |
26 | /*! |
27 | * Creates an instance that operates on the given filename |
28 | * using the compression filter associated to given mimetype. |
29 | * |
30 | * \a filename is a local path (e.g. "/home/weis/myfile.tgz") |
31 | * |
32 | * \a mimetype "application/gzip" (before 5.85: "application/x-gzip"), "application/x-bzip", |
33 | * "application/x-xz", "application/zstd" (since 5.82) |
34 | * "application/x-lzip" (since 6.15) |
35 | * Do not use application/x-compressed-tar or similar - you only need to |
36 | * specify the compression layer ! If the mimetype is omitted, it |
37 | * will be determined from the filename. |
38 | */ |
39 | explicit KTar(const QString &filename, const QString &mimetype = QString()); |
40 | |
41 | /*! |
42 | * Creates an instance that operates on the given device. |
43 | * |
44 | * The device can be compressed (KCompressionDevice) or not (QFile, etc.). |
45 | * |
46 | * \warning Do not assume that giving a QFile here will decompress the file, |
47 | * in case it's compressed! |
48 | * |
49 | * \a dev the device to read from. If the source is compressed, the |
50 | * QIODevice must take care of decompression |
51 | */ |
52 | explicit KTar(QIODevice *dev); |
53 | |
54 | /*! |
55 | * If the tar ball is still opened, then it will be |
56 | * closed automatically by the destructor. |
57 | */ |
58 | ~KTar() override; |
59 | |
60 | /*! |
61 | * Special function for setting the "original file name" in the gzip header, |
62 | * when writing a tar.gz file. It appears when using in the "file" command, |
63 | * for instance. Should only be called if the underlying device is a KCompressionDevice! |
64 | * |
65 | * \a fileName the original file name |
66 | */ |
67 | void setOrigFileName(const QByteArray &fileName); |
68 | |
69 | protected: |
70 | /// Reimplemented from KArchive |
71 | bool doWriteSymLink(const QString &name, |
72 | const QString &target, |
73 | const QString &user, |
74 | const QString &group, |
75 | mode_t perm, |
76 | const QDateTime &atime, |
77 | const QDateTime &mtime, |
78 | const QDateTime &ctime) override; |
79 | /// Reimplemented from KArchive |
80 | bool doWriteDir(const QString &name, |
81 | const QString &user, |
82 | const QString &group, |
83 | mode_t perm, |
84 | const QDateTime &atime, |
85 | const QDateTime &mtime, |
86 | const QDateTime &ctime) override; |
87 | /// Reimplemented from KArchive |
88 | bool doPrepareWriting(const QString &name, |
89 | const QString &user, |
90 | const QString &group, |
91 | qint64 size, |
92 | mode_t perm, |
93 | const QDateTime &atime, |
94 | const QDateTime &mtime, |
95 | const QDateTime &ctime) override; |
96 | /// Reimplemented from KArchive |
97 | bool doFinishWriting(qint64 size) override; |
98 | |
99 | /* |
100 | * Opens the archive for reading. |
101 | * Parses the directory listing of the archive |
102 | * and creates the KArchiveDirectory/KArchiveFile entries. |
103 | * \a mode the mode of the file |
104 | */ |
105 | bool openArchive(QIODevice::OpenMode mode) override; |
106 | bool closeArchive() override; |
107 | |
108 | bool createDevice(QIODevice::OpenMode mode) override; |
109 | |
110 | private: |
111 | protected: |
112 | void virtual_hook(int id, void *data) override; |
113 | |
114 | private: |
115 | class KTarPrivate; |
116 | KTarPrivate *const d; |
117 | }; |
118 | |
119 | #endif |
120 | |