C++文件容器(例如 zip)以便于访问

发布于 2024-10-05 01:39:32 字数 560 浏览 8 评论 0原文

我有很多小文件需要随我构建的应用程序一起提供,并且我想将这些文件放入存档中以使复制和重新分发更加容易。 我也非常喜欢将它们全部放在一个地方的想法,因此我只需要比较一个文件的 md5,以防出现问题。

我正在考虑一个类,它可以加载存档并返回存档中的文件列表,并在需要访问文件时将文件加载到内存中。

我已经在互联网上搜索了实现我想要的目标的不同方法,并找到了有关 zlib 和 lzma sdk 的信息。 两者都没有真正吸引我,因为我并没有真正发现 zlib 的可移植性,而且我不喜欢 lzma sdk,因为它太多了,我不想因为这个问题而毁掉应用程序。 zlib 的另一个缺点是我没有 C/C++ 经验(我对 C++ 真的很陌生)来了解手册中解释的所有内容。

我还必须补充一点,这是一个时间紧迫的问题。我花了一些时间来实现像 tar 这样的简单格式,以便我可以轻松访问应用程序中的文件,但我只是还没有时间这样做。

因此,我正在寻找一个允许我访问存档中的文件的库。如果有人能在这里指出正确的方向,我会很高兴。

提前致谢, 罗宾.

编辑:我需要在 Linux 和 Windows 下访问存档。抱歉我一开始没有提到这一点。

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.

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

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

发布评论

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

评论(6

萌︼了一个春 2024-10-12 01:39:32

对于压缩,我一直偏爱 ZipUtils,它使过程变得简单并且构建在 zlib 和 info-zip 库之上。

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.

半葬歌 2024-10-12 01:39:32

答案取决于您是否计划在最初构建存档后通过代码修改存档。

如果您不需要修改它,您可以使用 TAR - 这是一种方便且简单的格式。如果您想要压缩,您可以实现 tar.gz reader 或找到一些可以执行此操作的库(我相信有一些可用,包括开源库)。

如果您的应用程序需要随机访问数据或需要修改存档,那么常规 TAR 或 ZIP 存档并不好。虚拟文件系统(例如我们的 SolFS 或 CodeBase 文件系统)将更适合:虚拟文件系统适合存储的频繁修改,而归档主要针对一次写入多次读取的使用场景。

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.

旧时浪漫 2024-10-12 01:39:32

zlib 具有高度可移植性并且使用非常广泛。如果您无法理解 C++ 接口,还有许多其他语言的替代方案 - 请参阅“相关外部链接”此处< /a>.

在寻找不同的东西之前,先再看看。

zlib is highly portable and very widely used. if you can't make sense of the C++ interface, there are alternatives for many other languages - see 'Related External Links' here.

Take another look before you search for something different.

深巷少女 2024-10-12 01:39:32

如果您使用的是 Qt 或 Windows,您还可以将数据打包到可执行文件的资源区域中。您只需使用此技术分发可执行文件即可。已经编写并测试了一个定义良好的 API 来访问该数据。

If you're using Qt or Windows you can also pack data into the executable's resource area. You would only have to distribute the executable file using this technique. There's a well defined API already written and tested to access that data.

℉絮湮 2024-10-12 01:39:32

zlib API 是最佳选择。简单便携。查看 unzip.h 标头,了解访问存档文件的 API。它是用 C 编写的,而且非常简单。

如果文件很小,您可以将它们转储为字符串文字(搜索 bin2h 实用程序)并包含在您的项目中。然后更改读取文件的代码。如果当前使用 ifstream 类读取所有文件,只需将其更改为 istringstream 类并重新编译代码即可。

The zlib API is the way to go. Simple and portable. Lookat unzip.h header for APIs that access archive files. It is in C and very easy.

If the files are small, you can dump them into string literals (search for bin2h utility) and include in your project. Then change the code that read the files. If all files are currently read using ifstream class, simply changing it to istringstream class and recompile the code.

前事休说 2024-10-12 01:39:32

尝试使用 Quazip - 使用起来非常简单。您可以将其用作流,从中动态读取压缩文件。

Try using Quazip - it's quite simple to use. You can use it as a stream from which you read the compressed file on the fly.

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