title: Python - How to use custom buffer_size in io.BufferedReader?
body: <p>From what I understand, the <code>buffer_size</code> argument to <code>io.BufferedReader</code> is supposed to control the read buffer size passed to the underlying reader.</p>
  
  <p>However, I'm not seeing that behavior. Instead, when I <code>reader.read()</code> the entire file, <code>io.DEFAULT_BUFFER_SIZE</code> is used and <code>buffer_size</code> is ignored. When I <code>reader.read(length)</code>, <code>length</code> is used as buffer size, and the <code>buffer_size</code> argument is again ignored.</p>
  
  <p>Minimal example:</p>
  
  <pre><code>import io
  
  class MyReader(io.RawIOBase):
  
      def __init__(self, length):
          self.length = length
          self.position = 0
  
      def readinto(self, b):
          print('read buffer length: %d' % len(b))
          length = min(len(b), self.length - self.position)
          self.position += length
          b[:length] = 'a' * length
          return length
  
      def readable(self):
          return True
  
      def seekable(self):
          return False
  
  
  print('# read entire file')
  reader = io.BufferedReader(MyReader(20000), buffer_size=100)
  print('output length: %d' % len(reader.read()))
  
  print('\n# read part of file file')
  reader = io.BufferedReader(MyReader(20000), buffer_size=100)
  print('output length: %d' % len(reader.read(10000)))
  
  print('\n# read beyond end of file file')
  reader = io.BufferedReader(MyReader(20000), buffer_size=100)
  print 'output length: %d' % len(reader.read(30000))
  </code></pre>
  
  <p>Outputs:</p>
  
  <pre><code># read entire file
  read buffer length: 8192
  read buffer length: 8192
  read buffer length: 8192
  read buffer length: 8192
  read buffer length: 8192
  output length: 20000
  
  # read part of file file
  read buffer length: 10000
  output length: 10000
  
  # read beyond end of file file
  read buffer length: 30000
  read buffer length: 10000
  output length: 20000
  </code></pre>
  
  <p>Am I misunderstanding how the BufferedReader is supposed to work?</p>