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 Moved from ktar.h by Roberto Teixeira <maragato@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9#ifndef KARCHIVEFILE_H
10#define KARCHIVEFILE_H
11
12#include <karchiveentry.h>
13
14class KArchiveFilePrivate;
15/*!
16 * \class KArchiveFile
17 * \inmodule KArchive
18 *
19 * \brief A file in an archive.
20 *
21 * \sa KArchive
22 * \sa KArchiveDirectory
23 */
24class KARCHIVE_EXPORT KArchiveFile : public KArchiveEntry
25{
26public:
27 /*!
28 * Creates a new file entry. Do not call this, KArchive takes care of it.
29 * \a archive the entries archive
30 * \a name the name of the entry
31 * \a access the permissions in unix format
32 * \a date the date (in seconds since 1970)
33 * \a user the user that owns the entry
34 * \a group the group that owns the entry
35 * \a symlink the symlink, or QString()
36 * \a pos the position of the file in the directory
37 * \a size the size of the file
38 */
39 KArchiveFile(KArchive *archive,
40 const QString &name,
41 int access,
42 const QDateTime &date,
43 const QString &user,
44 const QString &group,
45 const QString &symlink,
46 qint64 pos,
47 qint64 size);
48
49 /*!
50 * Destructor. Do not call this, KArchive takes care of it.
51 */
52 ~KArchiveFile() override;
53
54 /*!
55 * Position of the data in the [uncompressed] archive.
56 * Returns the position of the file
57 */
58 qint64 position() const;
59 /*!
60 * Size of the data.
61 * Returns the size of the file
62 */
63 qint64 size() const;
64 /*!
65 * Set size of data, usually after writing the file.
66 * \a s the new size of the file
67 */
68 void setSize(qint64 s);
69
70 /*!
71 * Returns the content of this file.
72 *
73 * \note The data returned by this call is not cached.
74 *
75 * \warning This method loads the entire file content into memory at once. For large files or untrusted archives, this could cause excessive memory
76 * allocation. Consider reading in chunks using createDevice() instead when dealing with archives from untrusted sources.
77 */
78 virtual QByteArray data() const;
79
80 /*!
81 * This method returns QIODevice (internal class: KLimitedIODevice)
82 * on top of the underlying QIODevice. This is obviously for reading only.
83 *
84 * WARNING: Note that the ownership of the device is being transferred to the caller,
85 * who will have to delete it.
86 *
87 * The returned device auto-opens (in readonly mode), no need to open it.
88 * Returns the QIODevice of the file
89 */
90 virtual QIODevice *createDevice() const;
91
92 /*!
93 * Checks whether this entry is a file.
94 * Returns true, since this entry is a file
95 */
96 bool isFile() const override;
97
98 /*!
99 * Extracts the file to the directory \a dest
100 * \a dest the directory to extract to
101 * Returns true on success, false if the file (dest + '/' + name()) couldn't be created
102 */
103 bool copyTo(const QString &dest) const;
104
105protected:
106 void virtual_hook(int id, void *data) override;
107
108private:
109 KArchiveFilePrivate *const d;
110};
111
112#endif
113

source code of karchive/src/karchivefile.h