Actions
Bug #16737
closedFile::BINARY doesn't work
    Bug #16737:
    File::BINARY doesn't work
  
Description
File.open takes a mode argument which can be given as a string or as an integer using File::Constants.
When using the latter, the constant File::BINARY doesn't have any effect:
# this works:
File.open('foo', 'wb') do |f|
  p f.binmode?
  p f.external_encoding
end
#=> true
#=> #<Encoding:ASCII-8BIT>
# this doesn't:
File.open('foo', File::WRONLY|File::TRUNC|File::CREAT|File::BINARY) do |f|
  p f.binmode?
  p f.external_encoding
end
#=> false
#=> nil
Further inspecting File::BINARY reveals that it has a value of zero:
File::BINARY #=> 0
So it's no surprise that OR-ing it doesn't do anything.
I've tried various Ruby versions from 1.9.3 to 2.7.0 and all showed the above behavior. (I'm on macOS if that matters)
I'm aware that I can achieve the desired result by using a string mode or by passing binary: true. But since Ruby accepts mode to be given as an integer, there should be a (working) "b" equivalent.
Actions