Is there a portable C library to access .zip archives? "gzip" or "zlib" (the closest I could find) only handle compressed data, I need to be able to list the files inside the archive, and access each one individually, and if they're compressed using the 'deflate' method, I can use zlib on it.
Minizip, maybe?
http://www.winimage.com/zLibDll/minizip.html
The zip that comes with Linux and BSD is actually called info-ZIP which is here. Personally I have not tried such a thing but the info-zip front page states "Info-ZIP's primary compression engine has also been spun off into the free zlib compression library", so you might want to check out zlib. The zlib page has a FAQ with a answer to your specific question. I would start by studying how info-zip works. Good luck.
7-zip has a complete SDK, with example sources, and a lot of functionality.
take a look here
Related
i have a visual c project, where i want to include an archive containing multiple files in a directory structure
i would like to programmatically extract it to somewhere on the disk, using a preferably small library (under small i mean just a few .c and .h files - size doesnt really matter), but i only seem to find libraries that decompress or compress data directly (i looked over lzo-lzop-minilzo, but i dont seem to find anything that says it can decmpress an entire directory tree even tho i used lzop already to compress the archive with the files)
thanks
zlib and accompanying (in the contrib) minizip library support .zip format decompression.
You can pack the .zip file as a resource in your executable. To get the raw data from .exe use the FindResource, SizeofResource, LoadResource, LockResource APIs.
Then see minizip's samples to see how to decompress and read zlib's documentation to overload the I/O callbacks.
Disclaimer: I did this for Linderdaum Engine's virtual file system and there is now support for .zip, .tar, .rar (uncompressed) and .tar.gz formats. The code for VFS is in Src/Linderdaum/Core/VFS and it is under MIT license for non-commercial use. It's C++, but the I/O wrappers for zlib use C-style API and the code is pretty straightforward.
Is there a library for creating zip files (the zip file format not gzip or any other compression format) on-the-fly (so I can start sending the file while it is compressing) for very large files (4 Gb and above).
The compression ratio does not matter much (mostly media files).
The library has to have a c-interface and work on Debian and OSX.
libarchive supports any format you want, on the fly and even in-memory files.
zlib supports compressing by chunks. you should be able to start sending a small chunk right after compressing it, while the library is still compressing the next chunk. (see this example)
(unfortunately, the file table is stored at the end of the zip file, so the file will be unusable until it is complete on the receiver side)
While this question is old and already answered I will note a new potential solution for those that find this.
I needed something very similar, a portable and very small library that created ZIP archives in a streaming fashion in C. Not finding anything that fit the bill I created one that uses zlib, available here:
https://github.com/CTrabant/fdzipstream
That code only depends on zlib and essentially provides a simple interface to creating ZIP archives. Most importantly (for me) the output can be streamed to a pipe, socket, whatever as the output stream does not need to be seek-able. The code is very small, a single source file and a header file. Works on OSX and Linux and probably elsewhere. Hope it helps someone beyond just me...
How can I access to the contents of a zip file?
I'm trying write a program in C and I want use the libraries used by zip.
You may want to check the open source widely used library ZLIB.
The link provides sample code and the home page provides more information about the libraries, source code, installation and usage.
The Info-zip project has code for that.
Minizip, which is included with zlib is what you need. Look in the 'contribs' directory for the code. There is an example for zip/unzip and is easily included in a project.
Is there a standard way of reading a kind of configuration like INI files for Linux using C?
I am working on a Linux based handheld and writing code in C.
Otherwise, I shall like to know about any alternatives.
Final update:
I have explored and even used LibConfig. But the footprint is high and my usage is too simple. So, to reduce the footprint, I have rolled out my own implementation. The implementation is not too generic, in fact quite coupled as of now. The configuration file is parsed once at the time of starting the application and set to some global variables.
Try libconfig:
a simple library for processing structured configuration files, like this one: test.cfg. This file format is more compact and more readable than XML. And unlike XML, it is type-aware, so it is not necessary to do string parsing in application code.
Libconfig is very compact — a fraction of the size of the expat XML parser library. This makes it well-suited for memory-constrained systems like handheld devices.
The library includes bindings for both the C and C++ languages. It works on POSIX-compliant UNIX and UNIX-like systems (GNU/Linux, Mac OS X, Solaris, FreeBSD), Android, and Windows (2000, XP and later)...
No, there isn't one standard way. I'm sorry, but that is probably the most precise answer :)
You could look at this list of Linux configuration file libraries, though. That might be helpful.
Here are four options:
Iniparser
libini
sdl-cfg
RWini
If you can use the (excellent, in any C-based application) glib, it has a key-value file parser that is suitable for .ini-style files. Of course, you'd also get access to the various (very nice) data structures in glib, "for free".
There is an updated fork of iniparser at ccan, the original author has not been able to give it much attention over the years. Disclaimer - I maintain it.
Additionally, iniparser contains a dictionary that is very useful on its own.
If you need a fast and small code just for reading config files I suggest the inih
It loads the config file content just once, parse the content and calls a callback function for each key/value pair.
Really small. It can be used on embedded systems too.
I hate to suggest something entirely different in suggesting XML, but libexpat is pretty minimal, but does XML.
I came to this conclusion as I had the same question as you did, but then I realized the project already had libexpat linked-in--and I should probably just use that.
I'm looking for a bare bones simple example C app for unpacking a zip file using zlib. It must support fairly new version of .zip and must have source right down to the zlib calls.
The zlib-bin source package on my system (linux) has some example programs called "minizip" and "miniunzip" which shows just that.
The zpipe.c example on the zlib.net web site is pretty straight forward. There is also a pretty good description of what it does.