[#68478] Looking for MRI projects for Ruby Google Summer of Code 2015 — Tony Arcieri <bascule@...>

Hi ruby-core,

10 messages 2015/03/10

[ruby-core:68677] Re: [Ruby trunk - Bug #11015] [Open] IO.copy_stream does not advance Tempfile destination

From: Eric Wong <normalperson@...>
Date: 2015-03-30 00:16:04 UTC
List: ruby-core #68677
This happens because Tempfile is not an IO in MRI, and io.c calls
#to_path on it.  This means MRI reopens the file using a different
handle.

Using #to_io in this case avoids the extra open and writes to the
existing handle:

	IO.copy_stream(StringIO.new('foo'), file.to_io)

But yeah, I wish Tempfile were a subclass of IO in MRI, too...

Keep in mind, blindly calling #to_io isn't a good idea, either, since
some classes (gzip/zlib writer, SSL sockets, etc) only expose #to_io
for IO.select and we never want to write directly to those file handles.

In This Thread

Prev Next