I am aware that io.BytesIO()
returns a binary stream object which uses in-memory buffer. but also provides getbuffer()
which provides a readable and writable view (memoryview
obj) over the contents of the buffer without copying them.
obj = io.BytesIO(b'abcdefgh')
buf = obj.getbuffer()
Now, we know buf
points to underlying data and when sliced(buf[:3]
) returns a memoryview object again without making a copy. So I want to know, if we do obj.read(3)
does it also uses in-memory buffer or makes a copy ?. if it does uses in-memeory buffer, what is the difference between obj.read
and buf
and which one to prefer to effectively read the data in chunks for considerably very long byte objects ?