From: "windwiny (wind winy)" Date: 2013-11-27T15:25:13+09:00 Subject: [ruby-core:58629] [ruby-trunk - Bug #9164][Open] IO::foreach incorrect work for binary file on windows platform Issue #9164 has been reported by windwiny (wind winy). ---------------------------------------- Bug #9164: IO::foreach incorrect work for binary file on windows platform https://bugs.ruby-lang.org/issues/9164 Author: windwiny (wind winy) Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: 2.0.0p353,2.1.0dev Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN d2 = "123\n".b + "\x1a\xe8\xba\b".b + "\n789\n".b File.binwrite('1.txt', d2) p File.binread('1.txt').each_line.to_a # => ["123\n", "\x1A\xE8\xBA\b\n", "789\n"] p File.foreach('1.txt').to_a # => ["123\n"] Encoding.default_external = Encoding::UTF_8 p File.foreach('1.txt').to_a # => ["123\n"] Encoding.default_external = Encoding::ASCII_8BIT p File.foreach('1.txt').to_a # => ["123\n"] run above code on windows, File.foreach.to_a just return 1 row. run on mac and linux, that's correct, return 3 rows. -- http://bugs.ruby-lang.org/