Assume we have a file class with a single method called write, which persists bytes to disk:
f = File('/tmp/my/file.txt') f.write("hello world")
b = Buffer(f, bytes=1000) b.write("hello world") b.flush() Write a wrapper class for the file object which allows us to buffer the writes in-memory. The data should be flushed to disk when the buffer is full, or on demand with a method called flush. It should not use more memory than the max bytes allowed.