walac/pyusb — pull request #25 by wmvanvliet (2013-07-01 09:48:58+00:00)
Title: Add `read_into` function that reads into a pre-created buffer

I would like to propose a function analogous to [pySerial's `readinto`](http://pyserial.sourceforge.net/pyserial_api.html#serial.Serial.readinto) function.

Currently, the `read` function creates a new buffer of the requested size and fills it with data. This buffer is created at every call to this function, which is not optimal. To provide more flexibility, a `read_into` function could take a buffer, created by the user, as an argument and fill that one instead. Instead of returning the buffer, the function returns the number of bytes actually read.

The implementation given by this pull request redefines the `read` function as a wrapper around the `read_into` function, first creating the necessary buffer.