如何在 C# 中明智地存储大量序列化二进制文件?
我正在将大量对象序列化为二进制文件,但是我希望将所有内容整齐地组织起来,并且并不真正希望在一个文件夹中包含数百个文件。是否有办法将它们分组为 zip 文件,然后访问该 zip 中的各个文件?
例如,假设我创建了 100 个二进制文件并将它们压缩。我是否能够访问该 zip 中的单个文件并将其反序列化,而无需解压缩所有内容?
I'm serializing a large number of objects to binary files, however I want to keep everything neatly organized and don't really want hundreds of files in a folder. Is there anyway to group them into zip files, and then access the individual files within that zip?
For example, say I created 100 binary files and zipped them. Would I be able to access a single file in that zip and deserialize it without unzipping everything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,zip 有一个存档目录,允许跳转到特定文件。如果您打算花更多的时间从存档中读取而不是更改它,那么这应该是有效的。如果您必须能够将更改提交回非易失性存储,那么除 zip 之外的其他格式会更好。
您可以尝试的另一种方法是将 blob(二进制大型对象)存储在轻量级数据库中。
Yes, zip has an archive directory that allows jumping to a specific file. If you intend to spend much more time reading from the archive than changing it, this should be effective. If you have to be able to commit changes back to the non-volatile storage, then some other format besides zip would be better.
Another approach you could try would be storing blobs (binary large objects) in a lightweight database.
您可能想要使用 HDF5,这是一种用于结构化存储的文件格式和一组可使用的库它。
我仍然从未使用过它,但我必须在未来的项目中采用它。引用自他们的网站:
我知道他们提供了.net 的包装,你可以还可以找到一些其使用的 c# 示例。
You may want to use HDF5, a file format for structured storage and a set of libraries to work with it.
I still never used it, but I have to adopt it on a future project. Quoting from their site:
I know they provide a wrapper for .net, andy you can also find some c# example of its use.