title: When should one use BytesIO .getvalue() instead of .getbuffer()?
body: <p>According to the <a href="https://docs.python.org/3/library/io.html#io.BytesIO" rel="noreferrer">BytesIO docs</a>:</p>
  
  <blockquote>
    <p>getbuffer()</p>
    
    <p>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:</p>
    
    <p>getvalue()</p>
    
    <p>Return bytes containing the entire contents of the buffer.</p>
  </blockquote>
  
  <p>So it seems as if <code>getbuffer</code> is more complicated. But if you don't need a writable view? Would you then simply use <code>getvalue</code>? What are the trade-offs?</p>
  
  <h2>Minimal Example</h2>
  
  <p>In this example, it seems as if they do exactly the same:</p>
  
  <pre><code># Create an example
  from io import BytesIO
  bytesio_object = BytesIO(b"Hello World!")
  
  # Write the stuff
  with open("output.txt", "wb") as f:
      f.write(bytesio_object.getbuffer())
  </code></pre>