是否有类似 Filestorage 类的东西来存储文件?

发布于 2024-09-03 16:12:55 字数 672 浏览 3 评论 0原文

是否有类似类的东西可以用来存储文件和目录,就像使用 Zip 文件的方式一样?

由于我还没有找到任何“真正的”类来编写 Zip 文件(真正的类如 real 类中的那样), 如果能够将文件和目录存储在类似容器的文件中,那就太好了。

一个完美的 API 可能看起来像这样:

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();
}

...我希望你能明白这个想法。 重要的要求是:

  • 库必须是跨平台的
  • *在这种情况下 GPL 是不可接受的(MIT 和 BSD 许可证是)

我已经考虑过创建一个基于 SQLite 的实现(及其存储二进制 blob 的能力)。不幸的是,似乎不可能在 SQLite 数据库中存储目录结构,这使得它在这种情况下几乎毫无用处。

寄希望于这样的类库难道就没用了吗?

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 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦与时光遇 2024-09-10 16:12:55

在 SQLite 数据库中,您可以存储类似目录的结构...您只需要有一个“目录”表,每个目录有一个条目,至少有一个索引和一个“父”字段(它保存另一个目录的索引)目录,如果没有父目录则为 0)。然后你就可以有一个“Files”表,其中包含文件属性、父目录的索引和文件内容。

就是这样,现在您在关系数据库中拥有了目录树。

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.

梦冥 2024-09-10 16:12:55

有人向我指出 PhysicsFS,它的 API 与您描述的类似,但它是一个纯 C API你需要的一切。可以轻松编写一个简单的面向对象的包装器。

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.

昨迟人 2024-09-10 16:12:55

您可能想查看 http://www.cs.unc.edu/Research /compgeom/gzstream/

如果您自己制作,那么 redis 可能是比 SQLite 更好的选择,因为我相信它可以更好地处理二进制数据。

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.

闻呓 2024-09-10 16:12:55

我花时间围绕 libarchive 编写了一个小型但有效的包装器。我并不完全熟悉 Libarchive 的所有功能,但结果符合我的需要:

archive_wrapper.cpp @ gist.github.com

它使用 libmars 作为字符串等。但我想用 替换 mars::mstring 出现不会太难std::string
当然,这个包装器可以在 MIT/X11 许可证下使用(就像 libmars 一样),这意味着您可以用它做任何您想做的事情。 ;-)

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. ;-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文