Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ file container (e.g. zip) for easy access

Tags:

c++

zip

archive

I have a lot of small files I need to ship with an application I build and I want to put this files into an archive to make copying and redistributing more easy. I also really like the idea of having them all in one place so I need to compare the md5 of one file only in case something goes wrong.

I'm thinking about a class which can load the archive and return a list of files within the archive and load a file into memory if I need to access it.

I already searched the Internet for different methods of achieving what I want and found out about zlib and the lzma sdk. Both didn't really appeal to me because I don't really found out how portable zlib is and I didn't like the lzma sdk as it is just to much and I don't want to blow up the application because of this problem. Another downside with zlib is that I don't have the C/C++ experience (I'm really new to C++) to get everything explained in the manual.

I also have to add that this is a time critical problem. I though some time about implementing a simple format like tar in a way I can easy access the files within my application but I just didn't find the time to do that yet.

So what I'm searching for is a library that allows me to access the files within an archive. I'd be glad if anybody could point me in the right direction here.

Thanks in advance, Robin.

Edit: I need the archive to be accessed under linux and windows. Sorry I didn't mention that in the beginning.

like image 231
Robin Avatar asked Dec 01 '10 15:12

Robin


People also ask

Is a zip file a container?

A ZIP file is a container for other files. ZIP files compress their contents, which reduces downloading time. To download a ZIP file, click on a link to it; this will prompt your browswer to ask you if you would like to open or save the file.

How do I turn a folder into a zip file?

To unzip a single file or folder, open the zipped folder, then drag the file or folder from the zipped folder to a new location. To unzip all the contents of the zipped folder, press and hold (or right-click) the folder, select Extract All, and then follow the instructions.

Why can't I open a zip file?

Navigate to the folder location where the zip file was saved. Right-click on the zip file and choose Open with... Select Windows Explorer. If Windows Explorer is not an option, select Choose default program... and select Windows Explorer, then click OK.

Which module can help extract all of the files from a zip file?

extractall() method will extract all the contents of the zip file to the current working directory. You can also call extract() method to extract any file by specifying its path in the zip file. This will extract only the specified file.


2 Answers

For zipping, I've always been partial to ZipUtils, which makes the process easy and is built on top of the zlib and info-zip libraries.

like image 150
Billy ONeal Avatar answered Sep 23 '22 09:09

Billy ONeal


The answer depends on whether you plan to modify the archive via code after the archive is initially built.

If you don't need to modify it, you can use TAR - it's a handy and simple format. If you want compression, you can implement tar.gz reader or find some library that does this (I believe there are some available, including open-source ones).

If your application needs random access to the data or it needs to modify the archive, then regular TAR or ZIP archives are not good. Virtual file system such as our SolFS or CodeBase file system will fit much better: virtual file systems are suited for frequent modifications of the storage, while archives target mainly write-once-read-many usage scenarios.

like image 43
Eugene Mayevski 'Callback Avatar answered Sep 26 '22 09:09

Eugene Mayevski 'Callback