mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #5506: BytesIO objects now have a getbuffer() method exporting a
view of their contents without duplicating them. The view is both readable and writable.
This commit is contained in:
parent
6285774f06
commit
972ee13e03
7 changed files with 197 additions and 1 deletions
|
@ -785,6 +785,11 @@ class BytesIO(BufferedIOBase):
|
|||
raise ValueError("getvalue on closed file")
|
||||
return bytes(self._buffer)
|
||||
|
||||
def getbuffer(self):
|
||||
"""Return a readable and writable view of the buffer.
|
||||
"""
|
||||
return memoryview(self._buffer)
|
||||
|
||||
def read(self, n=None):
|
||||
if self.closed:
|
||||
raise ValueError("read from closed file")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue