PDA

View Full Version : Qt Wrapper for bzip2



wirasto
19th December 2009, 17:24
Who have Qt Wrapper for bzip2 ?

Lykurg
20th December 2009, 06:59
have a look at QuaZIP (http://quazip.sourceforge.net/).

wirasto
20th December 2009, 07:19
that just for zip. And for unzip is very slow on Linux.

Lykurg
20th December 2009, 07:58
that just for zip. And for unzip is very slow on Linux.
Well it uses the zlib library which is standard at Linux (Used by Apache, dpkg, git, Subversion, OpenSSL and may more...). And the speed is just fine for me but if you disagree then grab the C sources of bzip and go ahead coding your own wrapper.

Tanuki-no Torigava
20th December 2009, 11:30
Sorry Lykurg, but you are wrong. ZLib (http://zlib.net/) and BZip2 (http://www.bzip.org/) are different algorithms and uses different libraries.
Wirasto, as far as I know there is no BZip2 wrapper for Qt. But you can use zlib wrapper as a pattern or take bzip2 source code and reimplement the algorithm as Qt class by yourself. The only question - please share that ;) I think a lot of people will appreciate that.

Regards,
-- tanuki

squidge
20th December 2009, 14:55
I think Lykurg meant "Use ZIP which does have a Qt wrapper and used in many programs, or write your own wrapper for bzip". Heck, you could probably use most of the wrapper of zip for bzip, as they share a lot in common (apart from the obvious things like the actual algorithm, which will be in a seperate library anyway)

wirasto
21st December 2009, 04:31
this code form QuaZIP unzip sample


// Slow like hell (on GNU/Linux at least), but it is not my fault.
// Not ZIP/UNZIP package's fault either.
// The slowest thing here is out.putChar(c).
while(file.getChar(&c)) out.putChar(c);


How to change that code with Qt function ?

Tanuki-no Torigava
22nd December 2009, 21:23
How to change that code with Qt function ?

Use QByteArray and block operations.

squidge
22nd December 2009, 21:38
while(file.getChar(&c)) out.putChar(c);

How to change that code with Qt function ?
First thing I'd say is: WHY is it written like that? The comment seems to imply there was no alternative, which I find suprising. Are 'file' and 'out' internal classes for some reason? In which case you probably can't change it easily. If it's standard i/o however, then I'd find the end and read it in blocks which would be MUCH faster.

I'd probably use:
QByteArray QIODevice::read ( qint64 maxSize )
write ( const QByteArray & byteArray )

wysota
23rd December 2009, 00:24
I'm assuming "file" is a zip device and there is a chance it needs to be read byte by byte. In that case the only thing you can do is read byte by byte but then write block by block. If "out" is a zip device then of course you need to reverse what I've written here (i.e. read block by block and write byte by byte).

wirasto
24th December 2009, 05:08
Read byte by byte and write block by block ? I don't get what is your mean. Can you give me a sample code how to do that ?

squidge
24th December 2009, 09:45
Read into a QByteArray, and then write() that entire byte array when the size is >= a certain amount.