PDA

View Full Version : open/write gzipped file



niko
10th December 2006, 16:16
Hello,

I have gziped xml-files that are gziped. I can unzip then with gunzip on the commandline.
how can I open such a file in Qt?

there exists qCompress/qUncompress but this doesn't seem to work on .gz files.

I also found this: http://quazip.sourceforge.net/

... is there a simpler way that doens't need an extra dependendency?
(i don't need to write full zip-archives with multiple files etc.)

thanks,
niko

tzioboro
10th December 2006, 16:50
Maybe http://osdab.sourceforge.net/ will be more helpful ??

niko
10th December 2006, 19:16
thanks,

but it looks like another full-blown-zip-archive library - I need only gzipping one file (something more lightweight)

niko

tzioboro
10th December 2006, 19:21
So maybe using QProcess and gzip would be more suitable?

niko
10th December 2006, 20:37
that would be the easiest i guess...
but would work only on unix :(

or does something comparable exist on win32?

tzioboro
11th December 2006, 08:51
Yes, you might use gzip from Cygwin ... I guess ..

niko
11th December 2006, 10:22
sure, that will work

but the users of my application won't be happy about that :D

Brandybuck
11th December 2006, 18:55
zlib is fairly lightweight, you may want to try it. http://www.zlib.net/. This is the same compression library that Qt uses, but it doesn't expose the gzip functionality.

niko
11th December 2006, 20:19
i was thinking about that too.
but where to start?
could you give me some hints?

(i have almost no c++ experience)

thanks
niko

Brandybuck
11th December 2006, 21:42
zlib is C, not C++. I have never used it directly. My first step would be to read its documentation and look at any example programs. You may also want to look at the qCompress sources to see how Trolltech uses it.

niko
12th December 2006, 19:19
hooray, it works :D

this is how I did it:


gzFile file;
file = gzopen (fileName.toUtf8().data(), "rb");
if(!file) {
QMessageBox::critical(0, tr("import"), tr("Can't open file"));
return;
}
QByteArray input;
char buffer[1024];
QByteArray inputData;
while(int readBytes = gzread (file, buffer, 1024))
{
input.append(QByteArray(buffer, readBytes));
}
gzclose(file);


thanks for the help....

niko