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.
Related
The title basically says it all. It might be a dumb question (which probably is) because I am entirely new to programming. I wonder how the desktop apps we use are made of mostly .dll files when you check their program files, but not even a single source code file? Is there any way to open them, or how can I turn my code file into .dll?
Thats exactly what DLL files are. DLL files are libraries which contain code that is called by the 'main' source code, which is compiled into '.exe' files.
You not being able to see such code is intended by its owner, unless the source itself is released alongside the compiled software. A project may integrate .dll files already developed by someone else instead of developing them from scratch.
As to how to turn your code into a .dll, it would depend on the language you are developing in.
More detailed answers at: What exactly are DLL files, and how do they work?
Short answer: The DLL files are "compiled".
Compiled files no longer rely on their source code. Once compiled they can be executed by the operating system directly.
DLL files are not "scripts". In languages like HTML, Javascript and PHP, the files are interpreted at run time by the browser's HTML or Java engine or the PHP engine on a server. Thus you can also read them since they are not yet compiled. But in the case of a DLL file, the original source code files have been compiled (interpreted and converted) and the result is an executable Library which is used by another program to accomplish whatever tasks are in them.
It is possible to "decompile" them with a decompiler, but that will not give you the original source code, any more than a "jpg" will give you the original layered Photoshop file. All you have is the Result.
I was wondering if there was a specific set of library that can decompress tar.gz files in an rtems operating system. Most of the answer I seen is for linux. I was looking at gzip and libz but was not sure if these were for linux or can I use them for rtems as well.
There are some integrated functions that can extract tgz files in RTEMS. Take a look at the tar01 test for some examples with different sources (memory or file): https://git.rtems.org/rtems/tree/testsuites/libtests/tar01/init.c?id=8d989c56ff0c65beb7ec3390aebef6ea52840fab
Note that this is a test application intended to test the functionality. So some things might try to trigger expected failures. The test tar file is automatically generated by the Makefile, translated into some object file and linked into the application.
There is also the tarfs that can use a tar (not sure about tgz) as a read only file system. It's used in tar02 test.
Regarding libz: Although I haven't tried I would expect that it is possible to compile libz for RTEMS. If you need specifically that library you might want to ask on the RTEMS users mailing list whether someone already did that. There are a lot more RTEMS specific users and developers than on stackoverflow.
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...
My C application relies on some files to copy over. Will the files be contained in the executable and not as stand-alone files? Would it have to be linked statically? I am using Eclipse CDT if it matters.
There are several ways you can link file data into an executable. A platform like Windows allows you to link data into an executable as a "resource" and provides APIs to access those resources (this is how icons and other objects are bound into a Windows executable). This is probably the best way to do it if your platform supports it - support for it is built right into the IDEs.
At a lower level, you might be able to use the linker to directly link a file into an executable as an addressable object:
Embedding binary blobs using gcc mingw
And finally, if you're dealing with a more primitive system like some embedded platforms, you can run your file through something that converts it into source for C array of bytes:
Embed image in code, without using resource section or external images
Unless you do something special, no, the files will not be included in your executable. Is there a reason you can't distribute the text files with your application?
If you want to bake the files into your executable, you can bake them in constant strings:
const char myTextFileData[] = "the text of the file goes here";
Of course, you'll have to preprocess your text files into C source files (remembering to properly escape quotes, backslashes, newlines, and other control characters). Alternatively you can use a tool such as objcopy to convert the file data directly into an object file and then link that object file into your executable.
No. The executable contains only the output from the compiler and linker. Any ancillary files your program requires must be packaged separately.
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