Project

General

Profile

Actions

Bug #12989

closed

Passing `binmode: true` to `IO.pipe` makes `binmode?` return `true` but encoding is not binary

Added by tenderlovemaking (Aaron Patterson) over 7 years ago. Updated over 4 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.4.0dev (2016-11-16 gc-compact 56805) [x86_64-darwin16]
[ruby-core:78404]

Description

Here is a sample program:

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) 0001-Passing-binmode-true-to-IO.pipe-should-behave-like-b.patch tenderlovemaking (Aaron Patterson), 11/28/2016 10:31 PM
io-pipe-binmode.patch (2.87 KB) io-pipe-binmode.patch jeremyevans0 (Jeremy Evans), 07/25/2019 08:50 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0