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

Feature #17833: 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 4 years ago. Updated over 4 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

Updated by dsisnero (Dominic Sisneros) over 4 years ago Actions #1

  • Description updated (diff)

Updated by dsisnero (Dominic Sisneros) over 4 years ago Actions #2

  • Description updated (diff)

Updated by dsisnero (Dominic Sisneros) over 4 years ago Actions #3

  • Description updated (diff)
Actions

Also available in: PDF Atom