开发者

Is there something like a Filestorage class to store files in?

Is there something like a class that might be used to store Files and directories in, just like the way Zip files might be used?

Since I haven't found any "real" class to write Zip files (real class as in real class), It would be nice to be able to store Files and Directories in a container-like file.

A开发者_JS百科 perfect API would probably look like this:

int main()
{
    ContainerFile cntf("myContainer.cnt", ContainerFile::CREATE);
    cntf.addFile("data/some-interesting-stuff.txt");
    cntf.addDirectory("data/foo/");
    cntf.addDirectory("data/bar/", ContainerFile::RECURSIVE);
    cntf.close();
}

... I hope you get the Idea. Important Requirements are:

  • The Library must be crossplatform
  • anything *GPL is not acceptable in this case (MIT and BSD License are)

I already played with the thought of creating an Implentation based on SQLite (and its ability to store binary blobs). Unfortunately, it seems impossible to store Directory structures in a SQLite Database, which makes it pretty much useless in this case.

Is it useless to hope for such a class library?


In an SQLite db you can store directory-like structures... you just have to have a "Directories" table, with one entry for each directory, having at least an index and a "parent" field (which holds the index of another directory, or 0 if it has no parent). Then you can have a "Files" table, which contains file attributes, the index of the parent directory and the file content.

That's it, now you have your directory tree in a relational DB.


Someone pointed me to PhysicsFS, which has an API similar to what you describe, but it's a pure C API that does everything you need. A trivial object-oriented wrapper could be easily written.


You might like to check out http://www.cs.unc.edu/Research/compgeom/gzstream/

If you are making your own then redis may be a better choice than SQLite as I believe it handles binary data better.


I took the time to write a tiny, yet working wrapper around libarchive. I'm not exactly familiar with all features of Libarchive, but the result fits what I needed:

archive_wrapper.cpp @ gist.github.com

It uses libmars for strings, etc. But I guess it wouldn't be too hard to replace the mars::mstring occurances with std::string. And of course this wrapper is available under the MIT/X11 License (just as libmars), which means you can do whatever you want with it. ;-)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜