all Python 3ioterm
io.BufferedWriter
binary streams
A buffered binary write stream wrapping a raw stream; flushes in batches.
Syntax
io.BufferedWriter(raw)
Until the buffer fills up, whatever you wrote lives in process memory: if the program crashes or the stream is never closed, the file ends up empty or truncated, which is why you open it with a with-block. flush() hands the bytes to the operating system but does not guarantee they reached the physical disk — that takes os.fsync() on the descriptor. The wrapped raw stream must be writable; use BufferedReader for reading and BufferedRandom when you need both.
Examples
import io
raw = io.BytesIO()
w = io.BufferedWriter(raw)
w.write(b'hi')
w.flush()
print(raw.getvalue()) # → b'hi'
See also
Open in the full glossarydocs.python.orgReport an inaccuracy