CKTIS / Python
Module io
Provides raw, buffered binary and decoded text streams, including in-memory buffers.
Version: Python 3.14; repository image, production runtime not attested
Syntax
io.TextIOWrapper(buffer, encoding="utf-8")Provides raw, buffered binary and decoded text streams, including in-memory buffers.
BytesIO reads and writes bytes, while StringIO handles strings. A TextIOWrapper encodes strings for an underlying byte stream, so characters and byte counts may differ.
Flush the wrapper before inspecting buffered output.
Examples
import io
raw = io.BytesIO()
with io.TextIOWrapper(raw, encoding="utf-8", newline="") as text:
n = text.write("café")
text.flush()
print(n, len(raw.getvalue()), raw.getvalue().hex())
with io.StringIO("ab") as text:
print(text.read(1), text.read(), repr(text.read()))
Result
4 5 636166c3a9 a b ''
Flush the wrapper before inspecting buffered output.