quagzipfile.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef QUAZIP_QUAGZIPFILE_H
  2. #define QUAZIP_QUAGZIPFILE_H
  3. /*
  4. Copyright (C) 2005-2014 Sergey A. Tachenov
  5. This file is part of QuaZIP.
  6. QuaZIP is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU Lesser General Public License as published by
  8. the Free Software Foundation, either version 2.1 of the License, or
  9. (at your option) any later version.
  10. QuaZIP is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU Lesser General Public License for more details.
  14. You should have received a copy of the GNU Lesser General Public License
  15. along with QuaZIP. If not, see <http://www.gnu.org/licenses/>.
  16. See COPYING file for the full LGPL text.
  17. Original ZIP package is copyrighted by Gilles Vollant and contributors,
  18. see quazip/(un)zip.h files for details. Basically it's the zlib license.
  19. */
  20. #include <QIODevice>
  21. #include "quazip_global.h"
  22. #include <zlib.h>
  23. class QuaGzipFilePrivate;
  24. /// GZIP file
  25. /**
  26. 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.
  27. */
  28. class QUAZIP_EXPORT QuaGzipFile: public QIODevice {
  29. Q_OBJECT
  30. public:
  31. /// Empty constructor.
  32. /**
  33. Must call setFileName() before trying to open.
  34. */
  35. QuaGzipFile();
  36. /// Empty constructor with a parent.
  37. /**
  38. Must call setFileName() before trying to open.
  39. \param parent The parent object, as per QObject logic.
  40. */
  41. QuaGzipFile(QObject *parent);
  42. /// Constructor.
  43. /**
  44. \param fileName The name of the GZIP file.
  45. \param parent The parent object, as per QObject logic.
  46. */
  47. QuaGzipFile(const QString &fileName, QObject *parent = NULL);
  48. /// Destructor.
  49. virtual ~QuaGzipFile();
  50. /// Sets the name of the GZIP file to be opened.
  51. void setFileName(const QString& fileName);
  52. /// Returns the name of the GZIP file.
  53. QString getFileName() const;
  54. /// Returns true.
  55. /**
  56. Strictly speaking, zlib supports seeking for GZIP files, but it is
  57. poorly implemented, because there is no way to implement it
  58. properly. For reading, seeking backwards is very slow, and for
  59. writing, it is downright impossible. Therefore, QuaGzipFile does not
  60. support seeking at all.
  61. */
  62. virtual bool isSequential() const;
  63. /// Opens the file.
  64. /**
  65. \param mode Can be either QIODevice::Write or QIODevice::Read.
  66. ReadWrite and Append aren't supported.
  67. */
  68. virtual bool open(QIODevice::OpenMode mode);
  69. /// Opens the file.
  70. /**
  71. \overload
  72. \param fd The file descriptor to read/write the GZIP file from/to.
  73. \param mode Can be either QIODevice::Write or QIODevice::Read.
  74. ReadWrite and Append aren't supported.
  75. */
  76. virtual bool open(int fd, QIODevice::OpenMode mode);
  77. /// Flushes data to file.
  78. /**
  79. The data is written using Z_SYNC_FLUSH mode. Doesn't make any sense
  80. when reading.
  81. */
  82. virtual bool flush();
  83. /// Closes the file.
  84. virtual void close();
  85. protected:
  86. /// Implementation of QIODevice::readData().
  87. virtual qint64 readData(char *data, qint64 maxSize);
  88. /// Implementation of QIODevice::writeData().
  89. virtual qint64 writeData(const char *data, qint64 maxSize);
  90. private:
  91. // not implemented by design to disable copy
  92. QuaGzipFile(const QuaGzipFile &that);
  93. QuaGzipFile& operator=(const QuaGzipFile &that);
  94. QuaGzipFilePrivate *d;
  95. };
  96. #endif // QUAZIP_QUAGZIPFILE_H