Project

General

Profile

Actions

Bug #9164

closed

IO::foreach incorrect work for binary file on windows platform

Added by windwiny (wind winy) almost 11 years ago. Updated almost 11 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
2.0.0p353,2.1.0dev
[ruby-core:58629]

Description

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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0