From: "nobu (Nobuyoshi Nakada)" Date: 2022-05-19T07:27:56+00:00 Subject: [ruby-core:108618] [Ruby master Bug#18407] Behavior difference between integer and string flags to File creation Issue #18407 has been updated by nobu (Nobuyoshi Nakada). Status changed from Open to Closed Description updated `IO::BINARY` is for `O_BINARY` which comes from underlying runtimes, and unrelated to ruby encodings. The second form is for specifying such flags in a fine-grained manner, so it needs an encoding explicitly unlike the shorthand `"wb"`. ---------------------------------------- Bug #18407: Behavior difference between integer and string flags to File creation https://bugs.ruby-lang.org/issues/18407#change-97654 * Author: deivid (David Rodr��guez) * Status: Closed * Priority: Normal * ruby -v: 3.0.3 * Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN ---------------------------------------- Hi! I was under the impression that these two commands should either both work of both fail, however they behave differently. ```shell-session $ ruby -ropen-uri -EUTF-8:UTF-8 -e 'f = File.new("foo", "wb"); f.write URI.open("https://rubygems.org/gems/rake-13.0.6.gem").read' $ ruby -ropen-uri -EUTF-8:UTF-8 -e 'f = File.new("foo", File::WRONLY | File::TRUNC | File::BINARY); f.write URI.open("https://rubygems.org/gems/rake-13.0.6.gem").read' -e:1:in `write': "\\x8B" from ASCII-8BIT to UTF-8 (Encoding::UndefinedConversionError) from -e:1:in `
' ``` Could be an actual bug, and me misunderstanding the documentation. In any case it seemed worth reporting. -- https://bugs.ruby-lang.org/ Unsubscribe: