[issue21057] TextIOWrapper does not support reading bytearrays or memoryviews
STINNER Victor
report at bugs.python.org
Wed Mar 26 11:43:14 CET 2014
STINNER Victor added the comment:
> class MyByteStream(BytesIO):
> def read1(self, len_):
> return memoryview(super().read(len_))
> bs = MyByteStream(b'some data in ascii\n')
I guess that you are trying to implement a zero-copy I/O. The problem is that BytesIO does copy data. Example:
>>> data=b'abcdef'
>>> x=io.BytesIO(data)
>>> x.read() is data
False
Before trying to avoid copies in the "buffered" layer, something should be done for the "raw" layer (BytesIO in this case).
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21057>
_______________________________________
More information about the Python-bugs-list
mailing list