Python package bytesbufio
bytesbufio provides BytesBufferIO - an io.BytesIO implementation whose value can be accessed after it has been closed
Installation
pip install bytesbufio
Usage
import io
from bytesbufio import BytesBufferIO
bytesbuf = BytesBufferIO()
with io.TextIOWrapper(bytesbuf, encoding='utf-8') as textout:
textout.write("Hello world.")
text = bytesbuf.getvalue().decode('utf-8') # BytesIO would have raised an ValueError here
print(text)
Related
- Python Issue 22003 - BytesIO and shared bufferes
- Python Issue 23099 - value not available after close
License
Copyright (c) 2020 by Cornelius Buschka.