Gzip In-Memory Compression - c++

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.

Related

Is there an easy-to-use, platform-independent package that we can use to read & write gzip streams under C++?

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.

Text compression in C or C++

Compression text always gives me troubles if I have to do in C or C++ as there no inbuilt library is available by default unlike python and other languages,So I want to know what is the approach to be followed for text compression in these languages.
For an example consider this text,now which algorithm or method I should be used to compress this text and to get a very short possibly solution?
Go download zlib. Use the deflate functions.

Can I use dll in Turbo C++ program and do we have any dll for lzw compression and decompression

I was trying to create a lzw compression program. But i need to finish it by today itself so i want to use some dll for taking my input as txt file and output to as a text file. I want to do this in TURBO C++ code which are doing my remaining functionalities.
Can anyone suggest me some method.
Libzip isn't LZW (it uses an algorithm that's generally better), but it is probably the best standard answer. I don't know if there's a downloadable DLL for it in a standard location, so you might have to compile it from source.
Alternatively, a bit of Google-searching (on "lzw compression dll") found this C++ source code for doing LZW compression, which you may be able to use: http://zabkat.com/blog/24Jan10-lzw-compression-code.htm
this is an oldie question.
You can still look around the LHArc sources on the old Simtel archives. There's an implementation of LZW algorithm before it was patented by Compuserve.

Unzipping a directory in C++

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.

C++ cross-platform zlib simplifer-wrapper

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