将内容插入二进制文件或连接两个文件的最有效方法是什么
我们希望向二进制文件中插入一些内容,但希望 I/O 尽可能少。我们不想读第二部分然后写回来。有什么办法可以做到吗。理论上我们知道,文件在文件系统中是以块的形式保存的。我们可以打破区块链并在其之间插入一个新区块吗?
同样的想法也可以用于连接两个文件。一张一张地贴上去。有什么快速的方法可以做到这一点吗?
问题来自于写入一个大文件。我们想将其写入许多小文件并将它们连接在一起。
We want insert something into binary file, but want do I/O as less as possible. We don't want read the second part and write it back. Is there any way to do it. We know in theory, file are saved as blocks in file system. Could we just break the chain of blocks and insert a new one between it?
The same idea could also be used in join two files. Attach one after another. Is there any fast way to do this?
The problem comes from write a large file. We want write it to many small files and join them together.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想说不要去那里......
它将涉及低级的、文件系统特定的编码,可能会弄乱文件系统。
如果这对您的业务真的非常重要,也许您可以“模拟”文件内的块。然而,这将导致其他“方”(使用该文件的其他软件)无法解析其预期结构的文件。
I'd say don't go there...
It would involve low-level, file-system specific coding that could possibly mess up the file system.
If this is really, really important for you(r) business, perhaps you could 'emulate' blocks inside a file. This would however result in files of which the intended structure can not be resolved by other 'parties' (other software using the file).
您肯定不想直接弄乱文件系统。让操作系统来担心吧。如果您必须问这个问题,那么您可能不具备必要的知识来以比操作系统更高的效率来操作该级别的事物。
不要在大文件的中间添加数据,而是考虑一种不同的解决方案,允许您将数据附加到文件的末尾。 (或者是一些更有效的方法)。另外,如果您正在处理大量数据,也许数据库比庞大的文件更有效。
我有兴趣更多地了解您正在尝试做什么。也许有更简单的方法。
You most certainly don't want to go messing with the file system directly. Let the OS worry about that. If you have to ask this question, you probably don't have the requisite knowledge to manipulate things at that level with greater efficiency that the OS does.
Rather than adding data in the middle of a huge file, consider a different solution that allows you to append data to the end of the file. (Or is some more efficient way). Also, if you're dealing with a huge amount of data, maybe a database would be more efficient than a gargantuan file.
I would be interested in hearing more about what you're trying to do. Perhaps there's an easier way.