Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Solved] Compressing and uncompressing zip files: unclear documentation about qCompress and qUncompress functions
Hi to all,
Before starting in defining a compress/uncompress class working under Symbian and Meego I have tried a in-depth search of some API in the Qt documentation. The alternative is to start from the Qazip library and create a specific porting.
From the Doc menu here I searched with the "compress" keyword and I have found nothing. Thus I tried to see the Qt 4.7.4 Api library and searched manually in the list of all the documented Api functions.
The link is "here":http://developer.qt.nokia.com/doc/qt-4.7/functions.html and the first few description lines reports:
bq. This is the list of all documented member functions and global functions in the Qt API. Each function has a link to the class or header file where it is declared and documented.
Searching in this gigantic list I have found qCompress and qUncompress functions, that as I read in the description maybe useful to manage QByteArrays (downloaded from the web) in zip file format.
Both the functions links to a "global":http://developer.qt.nokia.com/doc/qt-4.7/qbytearray.html#id-53601555-1b4f-452e-b64e-43ce43317dfa keyword.
As I open the link surprisingly I see the QByteArray Class Reference documentation page. This landing page never mention these two functions!
Someone can explain this magic link ring? Is there a way to find somewhere the documentation for these two functions and (hopefully) know how I can use them in my code?
Any advice will be appreciated.
From what I understand qCompress/qUncompress are based on zlib and not compatible with zip. Is that your question?
If you found some issue in the documentation, please "file a bug report":http://bugreports.qt.nokia.com/ against it.
I have not clear two things, now that I read your post :)
Why qCompress / qUncompress are not compatibile with zip files if I have read somewhere that are for file zippped (probably I have not clear ideas on these aspects) and what is the difference between zip and zlib for compressing / uncompressing file?
The second question is: I have not idea if this is bug. I should to find the documentation on these fucntions before to know if the link is bugged or if these functions are part of QByteArray but are not documented...
Some advice ?
The "documentation":http://doc.qt.nokia.com/latest/qbytearray.html#qCompress-2 is very sparse on qCompress / qUncompress. As far as I know both functions are just "zlib":http://www.zlib.net/ wrappers.
Even though they can be used to uncompress data stored in ZIP archives you still need additional code which handles the ZIP archives themselves. The zlib package includes such code (minizip). A widely known Qt-style wrapper around this code is - as you've already found out - QuaZip.
So if it is about handling ZIP files you should start with QuaZip or your own wrapper around minizip. If it is just about handling archives in general you might select another archive format (tar for example).
As to the documentation: I usually use Google or Qt Creator to dig through the documentation. Both usually yield more suitable results then the QDN doc search.
[quote author="Alicemirror" date="1316096117"]Why qCompress / qUncompress are not compatibile with zip files if I have read somewhere that are for file zippped (probably I have not clear ideas on these aspects) and what is the difference between zip and zlib for compressing / uncompressing file? [/quote]
There is a difference between a compressed byte stream and an archive.
If you want to combine multiple files into a single compressed file there are two steps involved
- creating a single file out of multiple files (archive)
- compress this single file (compress)
Whereas the zlib can handle the second part well, it has no clue on how to split the resulting byte stream into multiple files. This where minizip shines.
A perfect example is compression in Linux, where both steps are still seperated. You first archive your data (tar) and then compress it (gzip, bzip2), which results in .tar.gz or .tar.bz2 files.
@Lukas: now things are more clear. So, first thanks :)
bq. Even though they can be used to uncompress data stored in ZIP archives you still need additional code which handles the ZIP archives themselves. The zlib package includes such code (minizip). A widely known Qt-style wrapper around this code is – as you’ve already found out – QuaZip.
As a matter of fact this is the case that I should handle: a web service send me a QByteStream containing a .zip file that includes at least two folders and a set of images. Thus we return to the Qazip library that I have already downlaoded. It seems a step impossible to avoid.
bq. As to the documentation: I usually use Google or Qt Creator to dig through the documentation. Both usually yield more suitable results then the QDN doc search.
Me too, but in this case I searched on the online doc because I was aware before that I need help so it is useful to post the links of the references in the discussion :)
bq. A perfect example is compression in Linux, where both steps are still seperated. You first archive your data (tar) and then compress it (gzip, bzip2), which results in .tar.gz or .tar.bz2 files.
I know this, so I have already searched for something like this but I can't decide how to do on the server side that send me a zip file only.
I think the easiest and fastest way is to go with QuaZip. As far as I can see it is licensed under the terms of the zlib license which permits intergration into commercial projects. And there is even recent development too. What more could one want ;-)
Me too. Many thanks Lukas. I have downloaded the sources anche cked them, are really well documented and already Qt-Oriented. Maybe not so difficult to recompile a version running for Symbian and Meego. My concern is only about the way to manage local libraries in Qt Quick applicaitons but I think that I will find some example about, i.e. the QPaint application shows the plugins management.
As to integration: the zlib license is very permissive. Just link it statically or even add the source to your project and compile it along with it.
Thank you for the suggestions. I saw that the QaZip includes also a Qt project. So I was unsure on what to do. I'll try to compile it stand alone to see what are the issues for the mobile devices then with a stable code I integrate in my application at all.
As it works I will prepare a open component based on this library. Maybe useful for a lot of people.
Many thanks for the help supporting the considerations above helping me to find a decision on how-to-proceed.
I will develop a QaZip derived version for Symbian and Meego.
wtgalaxysemi last edited by
KArchive seems now to be able to uncompress lot of different formats, not limited to Zip...