From: Eric Wong Date: 2013-08-10T19:53:34+00:00 Subject: [ruby-core:56522] Re: [ruby-trunk - Bug #8767][Open] IO.copy_stream should write in binary mode. "godfat (Lin Jen-Shin)" wrote: > This patch makes `IO.copy_stream' always copy in binary mode, I think your patch makes sense. > fixing the following scenario: > > require 'tempfile' > require 'stringio' > Encoding.default_internal = 'UTF-8' > out = Tempfile.new('out') > out.binmode > # before this patch it raises: > # in `write': "\xDE" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError) > IO.copy_stream(StringIO.new("\xDE\xAD\xBE\xEF"), out) Can make the above a testcase with your patch? > The other way to fix this would be trying to preserve the file mode > from Tempfile instead of always writing in binary mode. However, > this won't be the case for other objects responding to `to_path'. Please no :)