Actions
Feature #17833
openadd IO.readinto(b) where b is a bytes like object that is you can get a memoryview from
Status:
Open
Assignee:
-
Target version:
-
Description
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.
Related¶
Actions
Like0
Like0Like0Like0