This wiki is in the process of being archived due to lack of usage and the resources necessary to serve it — predominately to bots, crawlers, and LLM companies. Edits are discouraged.
Pages are preserved as they were at the time of archival. For current information, please visit python.org.
If a change to this archive is absolutely needed, requests can be made via the infrastructure@python.org mailing list.

This class is like StringIO for bytes objects. There are a few notes at the bottom.

In Python 2.6, 2.7 and 3.x, the io module provides a standard BytesIO class.

This is a toy implementation. Known holes are marked with XXX comments.

   1 class BytesIO(object):
   2     """ A file-like API for reading and writing bytes objects.
   3 
   4     Mostly like StringIO, but write() calls modify the underlying
   5     bytes object.
   6 
   7     >>> b = bytes()
   8     >>> f = BytesIO(b, 'w')
   9     >>> f.write(bytes.fromhex('ca fe ba be'))
  10     >>> f.write(bytes.fromhex('57 41 56 45'))
  11     >>> b
  12     bytes([202, 254, 186, 190, 87, 65, 86, 69])
  13     """
  14 
  15     def __init__(self, buf, mode='r'):
  16         """ Create a new BytesIO for reading or writing the given buffer.
  17 
  18         buf - Back-end buffer for this BytesIO.  A bytes object.
  19