Hex Fiend has an additional trick: it can save files in-place without needing additional disk space. It does this by computing a dependency graph, and then writing chunks in topological order. For example, say you have a 100 byte file, and the user inserts 100 bytes at the beginning. We get a graph:
[100, 200) depends on [0, 100)
[0, 100) from memory (no dependencies)
The topo sort means we'll write [100, 200) first, so its source data is not overwritten.Here is Hex Fiend's B+tree: https://github.com/HexFiend/HexFiend/blob/master/framework/s...