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¶
Updated by dsisnero (Dominic Sisneros) over 3 years ago
- Description updated (diff)
Updated by dsisnero (Dominic Sisneros) over 3 years ago
- Description updated (diff)
Updated by dsisnero (Dominic Sisneros) over 3 years ago
- Description updated (diff)
Actions
Like0
Like0Like0Like0