Issue #20067 has been updated by nobu (Nobuyoshi Nakada).
If the same encoding is specified for the internal and external encodings, it means that
no encoding conversion will occur.
That's what the internal encoding `nil` means.
```
$ ruby -e 'File.open(IO::NULL, "r:ASCII-8BIT:ASCII-8BIT") {|f| p
[f.internal_encoding, f.external_encoding]}'
[nil, #<Encoding:ASCII-8BIT>]
```
Regarding the external encoding of write-io, it feels something wrong a little.
----------------------------------------
Bug #20067: IO.pipe `int_enc` and `ext_enc` not working as documented?
https://bugs.ruby-lang.org/issues/20067#change-105737
* Author: byroot (Jean Boussier)
* Status: Open
* Priority: Normal
* Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
From the documentation:
pipe(ext_enc, int_enc, **opts)
If argument int_enc is given, it must be an Encoding
object or encoding name string that specifies the internal encoding to be used; if
argument ext_enc is also given, it must be an Encoding object or encoding name string that
specifies the external encoding to be used.
Test script:
```ruby
ios = IO.pipe(Encoding::BINARY, Encoding::BINARY)
p [:internal, *ios.map(&:internal_encoding)]
p [:external, *ios.map(&:external_encoding)]
Encoding.default_internal = Encoding::UTF_8
Encoding.default_external = Encoding::UTF_8
ios = IO.pipe(Encoding::BINARY, Encoding::BINARY)
p [:internal, *ios.map(&:internal_encoding)]
p [:external, *ios.map(&:external_encoding)]
```
Actual output:
```
[:internal, nil, nil]
[:external, #<Encoding:ASCII-8BIT>, nil]
[:internal, nil, nil]
[:external, #<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>]
```
Expected output:
```
[:internal, #<Encoding:ASCII-8BIT>, #<Encoding:ASCII-8BIT>]
[:external, #<Encoding:ASCII-8BIT>, #<Encoding:ASCII-8BIT>]
[:internal, #<Encoding:ASCII-8BIT>, #<Encoding:ASCII-8BIT>]
[:external, #<Encoding:ASCII-8BIT>, #<Encoding:ASCII-8BIT>]
```
Am I reading the documentation incorrectly, or is it just not working as claimed?
I tried on older versions, and it seems to have been like that all the way down to Ruby
1.9.
The only reliable way I found to have a "binary" pipe is to call `IO#binmode`.
--
https://bugs.ruby-lang.org/