File indexing completed on 2025-01-26 04:24:53
0001 #ifndef QUAZIP_QUAGZIPFILE_H 0002 #define QUAZIP_QUAGZIPFILE_H 0003 0004 /* 0005 Copyright (C) 2005-2014 Sergey A. Tachenov 0006 0007 This file is part of QuaZIP. 0008 0009 QuaZIP is free software: you can redistribute it and/or modify 0010 it under the terms of the GNU Lesser General Public License as published by 0011 the Free Software Foundation, either version 2.1 of the License, or 0012 (at your option) any later version. 0013 0014 QuaZIP is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 GNU Lesser General Public License for more details. 0018 0019 You should have received a copy of the GNU Lesser General Public License 0020 along with QuaZIP. If not, see <http://www.gnu.org/licenses/>. 0021 0022 See COPYING file for the full LGPL text. 0023 0024 Original ZIP package is copyrighted by Gilles Vollant and contributors, 0025 see quazip/(un)zip.h files for details. Basically it's the zlib license. 0026 */ 0027 0028 #include <QIODevice> 0029 #include "quazip_global.h" 0030 0031 #include <zlib.h> 0032 0033 class QuaGzipFilePrivate; 0034 0035 /// GZIP file 0036 /** 0037 This class is a wrapper around GZIP file access functions in zlib. Unlike QuaZip classes, it doesn't allow reading from a GZIP file opened as QIODevice, for example, if your GZIP file is in QBuffer. It only provides QIODevice access to a GZIP file contents, but the GZIP file itself must be identified by its name on disk or by descriptor id. 0038 */ 0039 class QUAZIP_EXPORT QuaGzipFile: public QIODevice { 0040 Q_OBJECT 0041 public: 0042 /// Empty constructor. 0043 /** 0044 Must call setFileName() before trying to open. 0045 */ 0046 QuaGzipFile(); 0047 /// Empty constructor with a parent. 0048 /** 0049 Must call setFileName() before trying to open. 0050 \param parent The parent object, as per QObject logic. 0051 */ 0052 QuaGzipFile(QObject *parent); 0053 /// Constructor. 0054 /** 0055 \param fileName The name of the GZIP file. 0056 \param parent The parent object, as per QObject logic. 0057 */ 0058 QuaGzipFile(const QString &fileName, QObject *parent = NULL); 0059 /// Destructor. 0060 virtual ~QuaGzipFile(); 0061 /// Sets the name of the GZIP file to be opened. 0062 void setFileName(const QString& fileName); 0063 /// Returns the name of the GZIP file. 0064 QString getFileName() const; 0065 /// Returns true. 0066 /** 0067 Strictly speaking, zlib supports seeking for GZIP files, but it is 0068 poorly implemented, because there is no way to implement it 0069 properly. For reading, seeking backwards is very slow, and for 0070 writing, it is downright impossible. Therefore, QuaGzipFile does not 0071 support seeking at all. 0072 */ 0073 virtual bool isSequential() const; 0074 /// Opens the file. 0075 /** 0076 \param mode Can be either QIODevice::Write or QIODevice::Read. 0077 ReadWrite and Append aren't supported. 0078 */ 0079 virtual bool open(QIODevice::OpenMode mode); 0080 /// Opens the file. 0081 /** 0082 \overload 0083 \param fd The file descriptor to read/write the GZIP file from/to. 0084 \param mode Can be either QIODevice::Write or QIODevice::Read. 0085 ReadWrite and Append aren't supported. 0086 */ 0087 virtual bool open(int fd, QIODevice::OpenMode mode); 0088 /// Flushes data to file. 0089 /** 0090 The data is written using Z_SYNC_FLUSH mode. Doesn't make any sense 0091 when reading. 0092 */ 0093 virtual bool flush(); 0094 /// Closes the file. 0095 virtual void close(); 0096 protected: 0097 /// Implementation of QIODevice::readData(). 0098 virtual qint64 readData(char *data, qint64 maxSize); 0099 /// Implementation of QIODevice::writeData(). 0100 virtual qint64 writeData(const char *data, qint64 maxSize); 0101 private: 0102 // not implemented by design to disable copy 0103 QuaGzipFile(const QuaGzipFile &that); 0104 QuaGzipFile& operator=(const QuaGzipFile &that); 0105 QuaGzipFilePrivate *d; 0106 }; 0107 0108 #endif // QUAZIP_QUAGZIPFILE_H