File indexing completed on 2025-02-16 13:00:36
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 2000-2005 David Faure <faure@kde.org> 0003 SPDX-FileCopyrightText: 2003 Leo Savernik <l.savernik@aon.at> 0004 0005 Moved from ktar.h by Roberto Teixeira <maragato@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 #ifndef KARCHIVEFILE_H 0010 #define KARCHIVEFILE_H 0011 0012 #include <karchiveentry.h> 0013 0014 class KArchiveFilePrivate; 0015 /** 0016 * @class KArchiveFile karchivefile.h KArchiveFile 0017 * 0018 * Represents a file entry in a KArchive. 0019 * @short A file in an archive. 0020 * 0021 * @see KArchive 0022 * @see KArchiveDirectory 0023 */ 0024 class KARCHIVE_EXPORT KArchiveFile : public KArchiveEntry 0025 { 0026 public: 0027 /** 0028 * Creates a new file entry. Do not call this, KArchive takes care of it. 0029 * @param archive the entries archive 0030 * @param name the name of the entry 0031 * @param access the permissions in unix format 0032 * @param date the date (in seconds since 1970) 0033 * @param user the user that owns the entry 0034 * @param group the group that owns the entry 0035 * @param symlink the symlink, or QString() 0036 * @param pos the position of the file in the directory 0037 * @param size the size of the file 0038 */ 0039 KArchiveFile(KArchive *archive, 0040 const QString &name, 0041 int access, 0042 const QDateTime &date, 0043 const QString &user, 0044 const QString &group, 0045 const QString &symlink, 0046 qint64 pos, 0047 qint64 size); 0048 0049 /** 0050 * Destructor. Do not call this, KArchive takes care of it. 0051 */ 0052 ~KArchiveFile() override; 0053 0054 /** 0055 * Position of the data in the [uncompressed] archive. 0056 * @return the position of the file 0057 */ 0058 qint64 position() const; 0059 /** 0060 * Size of the data. 0061 * @return the size of the file 0062 */ 0063 qint64 size() const; 0064 /** 0065 * Set size of data, usually after writing the file. 0066 * @param s the new size of the file 0067 */ 0068 void setSize(qint64 s); 0069 0070 /** 0071 * Returns the data of the file. 0072 * Call data() with care (only once per file), this data isn't cached. 0073 * @return the content of this file. 0074 */ 0075 virtual QByteArray data() const; 0076 0077 /** 0078 * This method returns QIODevice (internal class: KLimitedIODevice) 0079 * on top of the underlying QIODevice. This is obviously for reading only. 0080 * 0081 * WARNING: Note that the ownership of the device is being transferred to the caller, 0082 * who will have to delete it. 0083 * 0084 * The returned device auto-opens (in readonly mode), no need to open it. 0085 * @return the QIODevice of the file 0086 */ 0087 virtual QIODevice *createDevice() const; 0088 0089 /** 0090 * Checks whether this entry is a file. 0091 * @return true, since this entry is a file 0092 */ 0093 bool isFile() const override; 0094 0095 /** 0096 * Extracts the file to the directory @p dest 0097 * @param dest the directory to extract to 0098 * @return true on success, false if the file (dest + '/' + name()) couldn't be created 0099 */ 0100 bool copyTo(const QString &dest) const; 0101 0102 protected: 0103 void virtual_hook(int id, void *data) override; 0104 0105 private: 0106 KArchiveFilePrivate *const d; 0107 }; 0108 0109 #endif