Actions
Bug #8767
closedIO.copy_stream should write in binary mode.
Description
This patch makes `IO.copy_stream' always copy in binary mode,
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)
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'.
I think as we're treating destination as streams, we would always
want writing in binary. So I guess this is ok.
Thank you for reviewing.
This is discovered by using rubyzip, which is using Tempfile for
buffering input/output stream.
Commit on Github:
https://github.com/godfat/ruby/commit/94d9f3dd733fd19f5ade7b6e6f5bdf0c904e06c1
Files
Actions
Like0
Like0Like0Like0