KArchive

ktar.h
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 ktar.h KTar
14 *
15 * A class for reading / writing (optionally compressed) tar archives.
16 *
17 * KTar allows you to read and write tar archives, including those
18 * that are compressed using gzip, bzip2 or xz.
19 *
20 * @author Torben Weis <weis@kde.org>, David Faure <faure@kde.org>
21 */
22class KARCHIVE_EXPORT KTar : public KArchive
23{
24 Q_DECLARE_TR_FUNCTIONS(KTar)
25
26public:
27 /**
28 * Creates an instance that operates on the given filename
29 * using the compression filter associated to given mimetype.
30 *
31 * @param filename is a local path (e.g. "/home/weis/myfile.tgz")
32 * @param mimetype "application/gzip" (before 5.85: "application/x-gzip"), "application/x-bzip",
33 * "application/x-xz", "application/zstd" (since 5.82)
34 * Do not use application/x-compressed-tar or similar - you only need to
35 * specify the compression layer ! If the mimetype is omitted, it
36 * will be determined from the filename.
37 */
38 explicit KTar(const QString &filename, const QString &mimetype = QString());
39
40 /**
41 * Creates an instance that operates on the given device.
42 * The device can be compressed (KCompressionDevice) or not (QFile, etc.).
43 * @warning Do not assume that giving a QFile here will decompress the file,
44 * in case it's compressed!
45 * @param dev the device to read from. If the source is compressed, the
46 * QIODevice must take care of decompression
47 */
48 explicit KTar(QIODevice *dev);
49
50 /**
51 * If the tar ball is still opened, then it will be
52 * closed automatically by the destructor.
53 */
54 ~KTar() override;
55
56 /**
57 * Special function for setting the "original file name" in the gzip header,
58 * when writing a tar.gz file. It appears when using in the "file" command,
59 * for instance. Should only be called if the underlying device is a KCompressionDevice!
60 * @param fileName the original file name
61 */
62 void setOrigFileName(const QByteArray &fileName);
63
64protected:
65 /// Reimplemented from KArchive
66 bool doWriteSymLink(const QString &name,
67 const QString &target,
68 const QString &user,
69 const QString &group,
70 mode_t perm,
71 const QDateTime &atime,
72 const QDateTime &mtime,
73 const QDateTime &ctime) override;
74 /// Reimplemented from KArchive
75 bool doWriteDir(const QString &name,
76 const QString &user,
77 const QString &group,
78 mode_t perm,
79 const QDateTime &atime,
80 const QDateTime &mtime,
81 const QDateTime &ctime) override;
82 /// Reimplemented from KArchive
83 bool doPrepareWriting(const QString &name,
84 const QString &user,
85 const QString &group,
86 qint64 size,
87 mode_t perm,
88 const QDateTime &atime,
89 const QDateTime &mtime,
90 const QDateTime &ctime) override;
91 /// Reimplemented from KArchive
92 bool doFinishWriting(qint64 size) override;
93
94 /**
95 * Opens the archive for reading.
96 * Parses the directory listing of the archive
97 * and creates the KArchiveDirectory/KArchiveFile entries.
98 * @param mode the mode of the file
99 */
100 bool openArchive(QIODevice::OpenMode mode) override;
101 bool closeArchive() override;
102
103 bool createDevice(QIODevice::OpenMode mode) override;
104
105private:
106protected:
107 void virtual_hook(int id, void *data) override;
108
109private:
110 class KTarPrivate;
111 KTarPrivate *const d;
112};
113
114#endif
KArchive is a base class for reading and writing archives.
Definition karchive.h:41
virtual bool createDevice(QIODevice::OpenMode mode)
Can be reimplemented in order to change the creation of the device (when using the fileName construct...
Definition karchive.cpp:174
virtual bool doFinishWriting(qint64 size)=0
Called after writing the data.
virtual bool doWriteDir(const QString &name, const QString &user, const QString &group, mode_t perm, const QDateTime &atime, const QDateTime &mtime, const QDateTime &ctime)=0
Write a directory to the archive.
virtual bool doWriteSymLink(const QString &name, const QString &target, const QString &user, const QString &group, mode_t perm, const QDateTime &atime, const QDateTime &mtime, const QDateTime &ctime)=0
Writes a symbolic link to the archive.
virtual bool closeArchive()=0
Closes the archive.
virtual bool doPrepareWriting(const QString &name, const QString &user, const QString &group, qint64 size, mode_t perm, const QDateTime &atime, const QDateTime &mtime, const QDateTime &ctime)=0
This virtual method must be implemented by subclasses.
virtual bool openArchive(QIODevice::OpenMode mode)=0
Opens an archive for reading or writing.
A class for reading / writing (optionally compressed) tar archives.
Definition ktar.h:23
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:02:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.