拆分文件与源文件占用相同的内存空间 [英] Split file occupying the same memory space as source file

查看:145
本文介绍了拆分文件与源文件占用相同的内存空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,说100MB的大小。我需要把它分成(例如)4个不同的部分。
让我们说第一个文件从0-20MB,第二个20-60MB,第三个60-70MB,最后70-100MB。
但我不想做一个安全的拆分 - 4个输出文件。我想要做到这一点。所以输出文件应该使用这个源文件占用的硬盘上的相同位置,并且字面地分割它,而不进行复制(所以在分割的时候,我们应该放松原始文件)。
$ b 换句话说,输入文件是输出文件。



这是可能的,如果是,如何?

我想也许手动添加一个记录到文件系统,一个文件A从这里开始,并结束这里(在另一个文件的中间),执行4次,然后删除原始文件。但为此,我可能需要管理员权限,并且可能对文件系统不安全或健康。



编程语言并不重要,我只是感兴趣如果有可能的话。

解决方案

支持这种重新解释操作的文件系统API肯定是可能的(可以肯定的是,所需的分割可能并不是完全对齐于块边界,但是可以重新分配这些少量的边界块并仍然节省大量的临时空间)。

通用的文件系统抽象层都不支持这个;但回想一下,他们甚至不支持像插入模式这样合理的东西(当您将某些内容插入到文件中间而不是所有块中时,它们只会重写一个或两个块),而只是覆盖和附加模式。原因很大程度上是历史性的,但目前的模式是如此根深蒂固,不可能一个更丰富的API将很快变得普遍。


I have a file, say 100MB in size. I need to split it into (for example) 4 different parts. Let's say first file from 0-20MB, second 20-60MB, third 60-70MB and last 70-100MB. But I do not want to do a safe split - into 4 output files. I would like to do it in place. So the output files should use the same place on the hard disk that is occupied by this one source file, and literally split it, without making a copy (so at the moment of split, we should loose the original file).

In other words, the input file is the output files.

Is this possible, and if yes, how?

I was thinking maybe to manually add a record to the filesystem, that a file A starts here, and ends here (in the middle of another file), do it 4 times and afterwards remove the original file. But for that I would probably need administrator privileges, and probably wouldn't be safe or healthy for the filesystem.

Programming language doesn't matter, I'm just interested if it would be possible.

解决方案

The idea is not so mad as some comments paint it. It would certainly be possible to have a file system API that supports such reinterpreting operations (to be sure, the desired split is probably not exacly aligned to block boundaries, but you could reallocate just those few boundary blocks and still save a lot of temporary space).

None of the common file system abstraction layers support this; but recall that they don't even support something as reasonable as "insert mode" (which would rewrite only one or two blocks when you insert something into the middle of a file, instead of all blocks), only an overwrite and an append mode. The reasons for that are largely historical, but the current model is so entrenched that it is unlikely a richer API will become common any time soon.

这篇关于拆分文件与源文件占用相同的内存空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆