Project

General

Profile

Actions

Feature #17833

open

add IO.readinto(b) where b is a bytes like object that is you can get a memoryview from

Added by dsisnero (Dominic Sisneros) over 3 years ago. Updated over 3 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:103606]

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

#17834
#17831

Actions #1

Updated by dsisnero (Dominic Sisneros) over 3 years ago

  • Description updated (diff)
Actions #2

Updated by dsisnero (Dominic Sisneros) over 3 years ago

  • Description updated (diff)
Actions #3

Updated by dsisnero (Dominic Sisneros) over 3 years ago

  • Description updated (diff)
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0