What is the most efficient way to update a file

The simplest way to update a file is to write over the old data, but I need to be able to update a large file without long loading times, unfortunately Standard Library does not have an fs::File::update() function. I am considering using Bufreader/Writer to update it, but I feel like this is not the best way.

Are you looking for the std::io::Seek trait? It lets you change which part of a file any read/write operations are applied to and should let you jump to the exact place that needs updating.

1 Like

Looks promising, but I need to be able to avoid loading the entire file.

This doesn't load the entire file. It uses the APIs exposed by the OS to move the file's "cursor" and doesn't perform any reads.

3 Likes