add IO.readinto(b) where b is a bytes like object that is you can get a memoryview from
f = File.open(FILENAME,'rb') bytearray = ByteArray.new(File.size(FILENAME)) # ByteArray implements memoryview f.readinto(bytearray)
First, a ByteaArray is created and pre-allocated to the size of the data we're going to read into it. The pre-allocation is important - since readinto directly accesses the internal buffer of bytearray, it won't write more than has been allocated. Next, the file.readinto method is used to read the data directly into the bytearray's internal storage, without going via temporary buffers.