There’s a file that I would like to make sure does not grow larger than 2 GB (as it must run on a system that uses ext 2). What’s a good way to check a file’s size bearing in mind that I will be writing to this file in between checks? In particular, do I need to worry about buffered, unflushed changes that haven’t been written to disk yet?
Share
You could start with something like this:
Then you could use it like this:
Obviously, this implementation doesn’t work if you aren’t writing the file from scratch, but you could adapt your
__init__method to handle initial data. You might also need to override some other methods:writelines, for instance.This works regardless of encoding, as strings are just sequences of bytes.