How can I control when (or if) file writes are committed to disk?

Viewed 44

I have a file that's a big binary blob, and I'm writing an editor for that file. I want to make changes, but don't want them written to disk right away; I want the option of throwing them away without saving them.

What's a good way to do this?

Some things I thought of:

  1. Slurp the whole file into memory and edit it there. (What if the file is huge though?)
  2. Make a temp file and edit that. (Same problem)
  3. Make a file-like object that writes to an internal data structure that sits "in front of" the file.

#3 sounds like it would work. It also sounds like something someone has probably already done, and I just don't know the right search terms to plug into google.

I'm working in Python 3.

0 Answers
Related