I'm looking for a wrapper that distills zlib to:
OpenZipFile()
GetItemInfo(n)
UnzipItem(n) // Bonus points for unzipping recursively if item n is a directory.
I see a lot of wrappers around the zlib library on, say, codeproject.com but they are all platform-specific in order to provide the added platform-specific functionality of unzipping to file/memory buffer/pipe.
In boost::iostreams there is the possibility to use zlib, gzip and bzip2 formats.
You find it from http://www.boost.org/
In the zlib source archive, there is a contribution named "minizip".
"minizip" is a set of files you can use to play with .zip files. Basic services you need are already there :
unzOpen
unzLocateFile
unzOpenCurrentFile
unzGetCurrentFileInfo
unzCloseCurrentFile
unzClose
Of course, this is not object oriented (and I'm sure that was not the goal of the creator of minizip), but writing a simple object oriented wrapper should be easy.
firstobject's easy zlib stays cross-platform; it has zlib in a single file easyzlib.c and exposes only ezcompress and ezuncompress functions with the added feature of determining the memory requirement before allocating the exact size.
You could try to grab the code from another FOSS project. ScummVM, for example, has a highly portable Zlib wrapper (implementation, header) with all the functions you need, plus an OO layer for interfacing generically with any other kind of archive.
Maybe that's a good starting point? The wrapper functions are totally standalone and portable (heck, they even work on a Nintendo DS), but the OO layer depends on many custom classes which may be hard to add to your own project.
GZStream is worth a look. This is a nice cross-platform wrapper round ZLib which extend the STL iostream classes.
http://www.cs.unc.edu/Research/compgeom/gzstream/
What is good about this wrapper over some of the others is that if you're working with very large archives you don't need to load the whole dataset into memory.
If you will use minizip -- pay attention, thet version shipped with zlib 1.2.3 has 2GB resulting zip file limitation. IT will produce zip with size >2GB - but you won't be able to open them...
This is an old thread, but I thought I'd throw in Boost's ZLib wrapper:
http://www.boost.org/doc/libs/1_47_0/libs/iostreams/doc/classes/zlib.html
You can check also this C++ Zlib wrapper with auto-detection of input format:
https://github.com/mateidavid/zstr
Related
I would like to find some C++ packages that can function as what we have in the GZipStream Class (MSDN Description) in .NET Framework. I'm using them under Linux.
And I'd be dealing with large files (possibly GB or even TB sizes) so the efficiency of the gzipstream implementation is also a concern.
What's your advice?
You can always use the original ZLib library. It includes the functionality required to decompress gzip files.
Is there any C/C++ FLAC tagging library that work on streams? Wherever I look I only find ones that work on files. It's kinda weird to me - why use something limited like file instead of more abstract stream. Well, maybe I'm just spoiled by managed languages neatness (I'm more of a Java guy, but this time I need unmanaged code solution).
I'm not familiar with any FLAC libraries, but the reference FLAC library supports an interface for custom I/O. This allows you to write a small stub that will convert I/O calls to a custom data source, which needn't be a file.
It seems to require capacity to seek, though. If that is the case, then you might not be able to wrap a socket without a high-level protocol that allows you to seek.
I depend heavily on Python's standard library, both for useful data structures and manipulators (e.g., collections and itertools) and for utilities (e.g., optparse, json, and logging), to skip the boilerplate and just Get Things Done. Looking through documentation on the C++ standard library, it seems entirely about data structures, with little in the way of the "batteries included" in Python's standard library.
The Boost library is the only open-source C++ library collection I know of that resembles the Python standard library, however while it does have utility libraries such as Regular Expression support, most of it is also dedicated to data structures. I'm just really surprised that even something as simple as assured parsing and writing a CSV file, made delightfully simple with the Python csv module, looks to require rolling-your-own in C++ (even if you leverage some parsing library by Boost).
Are there other open-source libraries out there for C++ that provide "batteries"? If not, what do you do as a C++ programmer: hunt for individual utility libraries (and if so, how), or just roll your own (which seems annoying and wasteful)?
The Poco library is more like other languages' standard libraries.
Actually the Poco web site's logo says "C++ now comes with batteries included!", which seems to be precisely what you're asking for.
I didn't like it when I tried because I found it too C-like and with too many dependencies between parts (difficult to single out just the functionality you want).
But there are many people & firms using it, so it seems I'm in minority and you will perhaps find it very useful.
In addition, as others have mentioned, for data structures, parsers, and indeed an interface to Python!, and such stuff, check out Boost.
Cheers & hth.,
While C++ does offer many of the comforts extended by OO it keeps a very simple standard library. C++ has STL and Boost. These are very good, and have more then just datastructures.
If your needs are these sorts of higher order functions for prototyping or making application without intense (relative term) speed requirements then C/C++ is probably not the right choice for you. I believe you will find that for most projects that high level languages will be fast enough for your needs. If you are working on an application that requires C/C++ speed (and accompanying standard deviations) then you should probably invest your time carefully picking each individual library you will be using.
http://beta.boost.org/community/sandbox.html
http://www.boostpro.com/vault/
also you can google for "boost+bar", eg
boost log ->
http://boost-log.sourceforge.net/libs/log/doc/html/index.html
boost threadpool ->
http://threadpool.sourceforge.net/
http://www.boost.org/doc/libs/1_45_0/?view=categorized
Boost isn't just about data structures - it has lots of the batteries you want - parsing, threads, collections, logging, etc.
With C and C++ you typically won't find a "do it all" library, instead you'll use individual libraries that do different things. You can use one library that does JSON parsing, one that does crypto, one that does logging, etc.
Boost and Qt are the only ones that would be more of a "do it all" type library.
Quick and simple question.
There are examples online about achieving in-memory gzip compression with zlib (C++) WITHOUT external libraries (like boost or such)?
I just need to compress and decompress a block of data without much options. (it must be gzip as its the same format used by another mine C# program (the data is to be shared))
Tried to search to no avail...
Thanks!
You use an external library called zlib. You could statically link against this library if you did not want to bundle the DLL with your program.
zlib works happily with in-memory buffers.
You do not require boost.
This isn't a complete answer to your question, but you will probably be interested in How can I decompress a gzip stream with zlib?. There is a little bit of poorly documented magic that you need to supply in order for zlib to work with gzip streams.
The zlib API has many functions for doing in-memory compression that don't depend on actual files on disk.
I am creating a C++ program that will read a .docx's plain text. My plan of attack is to rename the .docx as a .zip and then unzip. I then will rename the .xml file containing the text of the document as a .txt and parse it out.
Right now I have figured out the renaming which was easy enough. I am now struggling with unzipping. I am very proficient in C++, but this is my first time I have been extending myself to real word applications and using it beyond the STL library.
At first I tried many wrappers for C++ from the zlib library, but have not been able to get any of them to compile or work properly (it may be due to environment being in Cygwin). For that reason it seems I have to default to using the messy zlib code to do this. But from all the documentation and examples I can find it only shows zlib being used to read a .zip that is a compression of one file not multiple files. I now don't know where to go from here and, like I said earlier, being completely new to the domain outside of STL I am feeling quite lost.
Any help or guidance is much appreciated!
Thanks,
Michael
I don't think zlib supports multi-file zips directly (could be wrong), so you may want to look for alternatives. As an aside, you might also want to consider switching from cygwin to MinGW, unless you really need the POSIX/UNIX compatibility that cygwin provides.
I've been dealing with a similar issue, but don't really have a great solution yet.
zlib does not currently support multiple files.
See: C/C++ Packing and Compression
zlib is for GZip compression, not ZIP compression (see here for details).
As a result you'd perhaps be better to shell out to the unzip utility provided in Cygwin and available for lots of platforms.