c++ - Archive files present in different directories and accessing single files - c++

I have many text files that are located in different directories -
dir1/.../textfiles/<various .txt files>
dir2/.../textfiles/<various .txt files>
and so on...
I need a c++ solution to compress and archive all these files present in different directories. I also need a way to search, decompress and open only a particular file in this archive.
One solution I can think of is to use system calls to create a tar archive.
I actually want a purely C++ based solution to this problem that is simple and fast and gives the desired result.
I searched a lot about this on the internet and found a few solutions like using Chilkat or libtar libraries but I do not intend to use them.
Another one that I found out is this.
Is there any simple C++ solution to this problem?

Related

Zip multiple files in C++

I have created ".tar" file and added multiple files in it while converting it to ".zip" i am facing problem.
I should create ".zip" for compress multiple files.
I need this in c++
code.BZ2 compression in C++ with bzlib.h I used this link to compress.
I tryed with http://www.winimage.com/zLibDll/minizip.html i feel its complicated.
please help me i am new to it Thank you so much in advance.
As far as I have used, Minizip is the best available open source to achieve this purpose. There are example classes, compress.c and uncompress.c which almost does everything related to zipping and unzipping

C/C++ Windows+Linux ZIP Library for only unpacking?

Continuation of:
Standalone Cross Platform (Windows/Linux)) File Compression for C/C++?
After many attempts on ZLIB ZZLIB LIBZIP MINIZIP I always get many problems at the compilation stage. Many google searches turned out OS-specific libraries and I can't really find anything that fit my 'simple' needs.
I reduced my needs for the library (Or wrapper?) to this:
Works on both Windows and Linux OR 2 separate libraries; one which works on Windows and the other one on Linux, I can make 2 separate projects for Windows and Linux if it is really neccesary
Unpack file from zip to specified directory
Check if file exists in zip file
C OR C++ OR Mixed (yeah, that doesn't matter)
Preferably Very Simple to include into any project
(eg 5 c/cpp files and 1-3 header files? anyway not tons files, when I open all the libzip and zlib archives I have something like: "O my ..")
I've checked many stackoveflow threads too with the words "Windows Linux ZIP C C++" but all the results seem so have libraries which I OR don't know how to compile OR is too difficult to use OR it has too many 'needed stuff' for just simple zip extract and check if file exists.
I had put that project away for a later date and begun it now, and all those compilation errors came up (especially that VC++2010 doesn't have the C-99 inttypes.h)
I have had very good experience with Zipstream C++ library which gives you a nice OOP way of handling zip files.
If your project already uses some of the bigger libs like Boost , then you could try to use the boost::iostreams with the gzip filter, however the functionality is somehow limited.
Or if you happen to use Poco take a look at they're implementation Poco::Zip

C/C++: Easily unzip to memory

I need to find a library that allows me to easily get a directory listing of all the files inside a ZIP archive and allows me to extract any given file inside the archive to memory (a buffer). Preferably, it should be a high-level library since my requirements aren't very complex (what I mentioned above is pretty much all I need).
Previously I tried PhysFS which has the behavior I need (easily access files inside an archive), but it's unsuitable because of other reasons (there are many archives and PhysFS would require me to mount all of them individually, which is not an option). Another library that kinda has the functionality I need is Chilkat, but it's shareware so I can't use it either.
Any other suggestions?
While .zip uses zlib http://zlib.net compression, it alone is not sufficient to get a directory listing from a .zip file.
You also need code that can read the .zip dictionary format. Check out Minizip http://www.winimage.com/zLibDll/minizip.html. It provides a code and simple zip/unzip command line executables.
edit 2 The code is entirely C (so is Zlib) -- the page has links to two c++ wrapper libs that both seem to be dead links.
How about zlib? http://zlib.net/ "A Massively Spiffy Yet Delicately Unobtrusive Compression Library (Also Free, Not to Mention Unencumbered by Patents)"

What is the fastest way to access files in a zip file?

What is the fastest way to read individual files (in a random fashion) from a zip file?
As I understand it, zip files have a directory that stores the individual file entries, and I could scan this directory to build an external index. Are there any standardized ways (i.e. existing libraries) that already do that? Or could I use a specialized type of zip file?
Scanning the directory and building the index is the fastest and best way to provide random access to the compressed entries archived in a zip file. The directory is usually small and lies at the end of the archive. If you have seekable media, then this is what you want.
The zip format is documented pretty well; it's not too hard to do. The devil is in the details, though. If your zip files use ZIP64 extensions, encryption, split archives.. that's when it gets tricky. For simple zip files, doing what you imagine is not so difficult.
Still it would be easier to use an external library.
Minizip seems to be a good library for reading or writing zip files. It uses the zlib library.
http://www.winimage.com/zLibDll/minizip.html

Sequential File Access, load multiple text files in project directory using C++

Is it possible to load multiple files from a project directory. For example, loading FileA.txt, FileB.txt, and FileC.txt from a folder (raw/assets) within the project folder?
Any help would be much appreciated.
Since your comment says you're targetting Windows, take a look at this API function:
http://msdn.microsoft.com/en-us/library/aa364418%28VS.85%29.aspx
Find files matching your pattern and deal with them
http://www.cplusplus.com/doc/tutorial/files/