Using ValueTreeSynchroniser to write back to disk

The app I’m working on has its entire state backed by a ValueTree. When I save, I’d like to be able to write back only the parts that have changed to disk rather than clobbering the whole file by writing back the entire state.

Is there a way to do this? ValueTreeSynchroniser looks extremely promising, but it only seems to be able to apply deltas to live ValueTree objects. Is there any clever way the binary delta could be written back to an on-disk ValueTree?

I think you’d be wasting your time going down that path - you can’t insert/delete from a file, so unless you’re replacing a section with some data that’s exactly the same size, you’ll save almost no work by doing this. And writing to disk is pretty fast. And to work out which part to modify, you’d still have to generate the entire new file, and read the old one, AND you’d have to do a diff, which is a really really expensive operation! It’d end up much slower than just writing the whole file!

But a useful shortcut is to avoid overwriting a file if nothing has changed - we do this a lot in the projucer, and have a utility function for it called FileHelpers::overwriteFileWithNewDataIfDifferent() which you might want to copy

1 Like

Good points all around. Thanks for the advice!