95 int zlibResult = Z_OK;
102 zlibStream.next_in = Z_NULL;
103 zlibStream.avail_in = 0;
104 zlibStream.avail_out = 0;
105 zlibStream.zalloc = Z_NULL;
106 zlibStream.zfree = Z_NULL;
107 zlibStream.opaque = Z_NULL;
110 if (inflateInit2(&zlibStream, MAX_WBITS + 16) != Z_OK) {
111 qWarning(
"Cannot initialize zlib, because: %s",
112 (zlibStream.msg != NULL ? zlibStream.msg :
"Unknown error"));
116 bool stillMoreWorkToDo =
true;
117 while (stillMoreWorkToDo) {
119 if (!zlibStream.avail_in) {
120 source = device->
read(CHUNK_SIZE);
125 zlibStream.avail_in = source.
size();
126 zlibStream.next_in =
reinterpret_cast<Bytef*
>(source.
data());
131 int oldSize = destination.
size();
132 destination.
resize(oldSize + CHUNK_SIZE);
133 zlibStream.next_out =
reinterpret_cast<Bytef*
>(
134 destination.
data() + oldSize - zlibStream.avail_out);
137 zlibResult =
inflate(&zlibStream, Z_NO_FLUSH);
138 switch (zlibResult) {
143 inflateEnd(&zlibStream);
144 qWarning(
"Error while inflating gzip file: %s",
145 (zlibStream.msg != NULL ? zlibStream.msg :
"Unknown error"));
146 destination.
chop(zlibStream.avail_out);
153 }
while (!zlibStream.avail_out);
155 if (zlibResult == Z_STREAM_END) {
157 if (!(zlibStream.avail_in && inflateReset(&zlibStream) == Z_OK))
158 stillMoreWorkToDo =
false;
163 destination.
chop(zlibStream.avail_out);
165 inflateEnd(&zlibStream);
void chop(int n)
Removes n bytes from the end of the byte array.
char * data()
Returns a pointer to the data stored in the byte array.
bool isReadable() const
Returns true if data can be read from the device; otherwise returns false.
The QByteArray class provides an array of bytes.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read...
bool isOpen() const
Returns true if the device is open; otherwise returns false.
Q_CORE_EXPORT void qWarning(const char *,...)
static int inflate(Bytef *dest, ulong *destLen, const Bytef *source, ulong sourceLen)
void resize(int size)
Sets the size of the byte array to size bytes.
int size() const
Returns the number of bytes in this byte array.
virtual bool open(OpenMode mode)
Opens the device and sets its OpenMode to mode.
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.