Issue #12989 has been updated by jeremyevans0 (Jeremy Evans).

File io-pipe-binmode.patch added

nobu (Nobuyoshi Nakada) wrote:
> Encoding argument should be prior to `binmode` option.
> 
> ```ruby
> open(IO::NULL, "r", binmode: true){|f| p [f.binmode?, f.external_encoding]} #=> [true, #<Encoding:ASCII-8BIT>]
> open(IO::NULL, "r:utf-8", binmode: true){|f| p [f.binmode?, f.external_encoding]} #=> [true, #<Encoding:UTF-8>]
> ```
> 
> Your patch always makes `external_encoding` `ASCII-8BIT` when `binmode` is set, even if an encoding is given.

Here's an updated patch based on tenderlove's original patch that does not change the encoding of the returned IO objects if encoding arguments are given in addition to the `binmode` option. Is this acceptable?

----------------------------------------
Bug #12989: Passing `binmode: true` to `IO.pipe` makes `binmode?` return `true` but encoding is not binary
https://bugs.ruby-lang.org/issues/12989#change-80038

* Author: tenderlovemaking (Aaron Patterson)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.4.0dev (2016-11-16 gc-compact 56805) [x86_64-darwin16]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
Here is a sample program:

~~~ruby
Encoding.default_external = Encoding::UTF_8
Encoding.default_internal = Encoding::UTF_8

reader, writer = IO.pipe(binmode: true)
reader.binmode?           # => true
reader.external_encoding  # => #<Encoding:UTF-8>
writer.binmode?           # => true
writer.external_encoding  # => #<Encoding:UTF-8>

reader, writer = IO.pipe
reader.binmode
writer.binmode

reader.binmode?           # => true
reader.external_encoding  # => #<Encoding:ASCII-8BIT>
writer.binmode?           # => true
writer.external_encoding  # => #<Encoding:ASCII-8BIT>
~~~

I think that passing `binmode: true` to `IO.pipe` should behave the same way as calling `binmode` on each file.  Today, passing `binmode: true` to IO.pipe puts the files in a strange state: they are binary and not binary.

I've attached a patch to fix the problem.

---Files--------------------------------
0001-Passing-binmode-true-to-IO.pipe-should-behave-like-b.patch (2.5 KB)
io-pipe-binmode.patch (2.87 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>