summaryrefslogtreecommitdiffstats
path: root/Doc/library/io.rst
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-09-06 18:48:21 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-09-06 18:48:21 (GMT)
commit972ee13e037432497fa003d4a786b2342a38db94 (patch)
treeab6585ebe7d0da0e725da7bd6f61a4cf739192f2 /Doc/library/io.rst
parent6285774f06f44f04353801cc79fd2a5e67f884ec (diff)
downloadcpython-972ee13e037432497fa003d4a786b2342a38db94.zip
cpython-972ee13e037432497fa003d4a786b2342a38db94.tar.gz
cpython-972ee13e037432497fa003d4a786b2342a38db94.tar.bz2
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.
Diffstat (limited to 'Doc/library/io.rst')
-rw-r--r--Doc/library/io.rst18
1 files changed, 18 insertions, 0 deletions
diff --git a/Doc/library/io.rst b/Doc/library/io.rst
index 2476acc..e61aa90 100644
--- a/Doc/library/io.rst
+++ b/Doc/library/io.rst
@@ -518,6 +518,24 @@ In many situations, buffered I/O streams will provide higher performance
:class:`BytesIO` provides or overrides these methods in addition to those
from :class:`BufferedIOBase` and :class:`IOBase`:
+ .. method:: getbuffer()
+
+ Return a readable and writable view over the contents of the buffer
+ without copying them. Also, mutating the view will transparently
+ update the contents of the buffer::
+
+ >>> b = io.BytesIO(b"abcdef")
+ >>> view = b.getbuffer()
+ >>> view[2:4] = b"56"
+ >>> b.getvalue()
+ b'ab56ef'
+
+ .. note::
+ As long as the view exists, the :class:`BytesIO` object cannot be
+ resized.
+
+ .. versionadded:: 3.2
+
.. method:: getvalue()
Return ``bytes`` containing the entire contents of the buffer.