Link to home
Start Free TrialLog in
Avatar of Jicova
Jicova

asked on

C++ standard library based binary archive format

I'm looking for some direction on a problem which I'm undertaking primarily as an exercise to beef up my familiarity with working with files in C++ beyond the basics. It's an area where I'm fairly weak, and my attempts to learn it from tutorials generally available online thus far has been fairly frustrating. I've found a fair amount of dated, incomplete, or too complex examples so far. One recommendation I saw was to look at the code behind projects like 7-Zip, but I think this falls on the complex side because of the size of a project like that. This quetion isn't intended to solve a specific problem or project, so I apologize if this all sounds fairly open-ended and lacking in direction. :)

I'm looking to write (at first) a relatively simple, no-frills class that can write and read a binary archive which contains files of varying types (images, text, audio). I've found some initial examples but they seem to all be very heavily dependent upon Windows APIs. For my purposes, I'd like it to have no dependencies other than C++14 and the Standard Library. I don't have a lot of experience with Boost, but that'd probably be fine as well. The goal would be to store files in this single archive and stream them in as needed when the application that uses it is running. I'm not necessarily interested in compression at this point, because I'm just trying to learn the fundamentals of this. Encryption of the contents is also not an interest of mine at this point. I figure once I have the basic approach sorted out, I can play with adding these things in for added challenge.

My understanding of this at a basic level is that, to do it right, I need to define a header entity which contains a file identifier that I create, version information, and a table of contents that is used to tell the program where to find the requested resource within the archive.  

Is there a good/comprehensive example of this process out there for a novice, or in a similar question that's been resolved here on EE? A cursory search didn't turn up exactly what I was looking for, but I may have missed something. One thing that has me a bit confused is whether this approach to archiving file assets is practical. I see a lot of references (particularly with respect to archiving file assets with Java) to serialization, which I similarly don't have much experience with at all. Is it a waste of time trying to learn the method I've described here?
SOLUTION
Avatar of evilrix
evilrix
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
As for serialisation, Boost has a very nice module for this.


http://www.boost.org/doc/libs/1_59_0_b1/libs/serialization/doc/index.html
Avatar of phoffric
phoffric

Yes, libarchive is an excellent library and easy to read the code. But IIRC, I thought it was written in C, not C++.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
To be completely honest, I wouldn't hold up the 7zip code as a particularly great example of good codemanship. 😊