30 class QuaGzipFilePrivate {
34 inline QuaGzipFilePrivate(): gzd(NULL) {}
35 inline QuaGzipFilePrivate(
const QString &fileName):
36 fileName(fileName), gzd(NULL) {}
37 template<
typename FileId>
bool open(FileId
id,
38 QIODevice::OpenMode mode, QString &error);
39 gzFile
open(
int fd,
const char *modeString);
40 gzFile
open(
const QString &name,
const char *modeString);
43 gzFile QuaGzipFilePrivate::open(
const QString &name,
const char *modeString)
45 return gzopen(QFile::encodeName(name).constData(), modeString);
48 gzFile QuaGzipFilePrivate::open(
int fd,
const char *modeString)
50 return gzdopen(fd, modeString);
53 template<
typename FileId>
54 bool QuaGzipFilePrivate::open(FileId
id, QIODevice::OpenMode mode,
58 modeString[0] = modeString[1] =
'\0';
59 if ((mode & QIODevice::Append) != 0) {
60 error = QuaGzipFile::trUtf8(
"QIODevice::Append is not "
61 "supported for GZIP");
64 if ((mode & QIODevice::ReadOnly) != 0
65 && (mode & QIODevice::WriteOnly) != 0) {
66 error = QuaGzipFile::trUtf8(
"Opening gzip for both reading"
67 " and writing is not supported");
69 }
else if ((mode & QIODevice::ReadOnly) != 0) {
71 }
else if ((mode & QIODevice::WriteOnly) != 0) {
74 error = QuaGzipFile::trUtf8(
"You can open a gzip either for reading"
75 " or for writing. Which is it?");
78 gzd =
open(
id, modeString);
80 error = QuaGzipFile::trUtf8(
"Could not gzopen() file");
88 d(new QuaGzipFilePrivate())
94 d(new QuaGzipFilePrivate())
100 d(new QuaGzipFilePrivate(fileName))
114 d->fileName = fileName;
130 if (!
d->open(
d->fileName, mode, error)) {
131 setErrorString(error);
134 return QIODevice::open(mode);
140 if (!
d->open(fd, mode, error)) {
141 setErrorString(error);
144 return QIODevice::open(mode);
149 return gzflush(
d->gzd, Z_SYNC_FLUSH) == Z_OK;
160 return gzread(
d->gzd, (voidp)data, (
unsigned)maxSize);
167 int written = gzwrite(
d->gzd, (voidp)data, (
unsigned)maxSize);
virtual bool isSequential() const
Returns true.
QString getFileName() const
Returns the name of the GZIP file.
virtual bool open(QIODevice::OpenMode mode)
Opens the file.
virtual void close()
Closes the file.
virtual ~QuaGzipFile()
Destructor.
QuaGzipFile()
Empty constructor.
virtual qint64 writeData(const char *data, qint64 maxSize)
Implementation of QIODevice::writeData().
virtual qint64 readData(char *data, qint64 maxSize)
Implementation of QIODevice::readData().
virtual bool flush()
Flushes data to file.
void setFileName(const QString &fileName)
Sets the name of the GZIP file to be opened.