From: Run Paint Run Run Date: 2009-06-25T17:15:13+09:00 Subject: [ruby-core:24029] [Bug #1689] ARGF.binmode Affects Encoding Inconsistently Bug #1689: ARGF.binmode Affects Encoding Inconsistently http://redmine.ruby-lang.org/issues/show/1689 Author: Run Paint Run Run Status: Open, Priority: Low Category: M17N ruby -v: ruby 1.9.2dev (2009-06-21 trunk 23774) [i686-linux] The IO#binmode documentation promises that "content is treated as ASCII-8BIT". I assumed this would apply to ARGF, too. It sometimes does: $ echo "a" | ruby -ve 'ARGF.binmode; p ARGF.readpartial(1).encoding' ruby 1.9.2dev (2009-06-21 trunk 23774) [i686-linux] # But often doesn't: $ echo "a" | ruby -ve 'ARGF.binmode; p ARGF.read.encoding' ruby 1.9.2dev (2009-06-21 trunk 23774) [i686-linux] # $ echo "a" | ruby -ve 'ARGF.binmode; p ARGF.getc.encoding' ruby 1.9.2dev (2009-06-21 trunk 23774) [i686-linux] # $ echo "a" | ruby -ve 'ARGF.binmode; p ARGF.readchar.encoding' ruby 1.9.2dev (2009-06-21 trunk 23774) [i686-linux] # $ ruby -ve 'ARGF.binmode; p ARGF.read.encoding' /usr/bin/ruby ruby 1.9.2dev (2009-06-21 trunk 23774) [i686-linux] # I had assumed that ARGF.binmode would set the encoding of all files read in to ASCII-8BIT. This is how, for instance, File works: File.binmode sets the output of File.read to ASCII-8BIT, even when the contents is entirely ASCII. Setting the default external encoding to ASCII-8BIT fixes these cases. So. given that I'm trying to document ARGF, my questions are: 1) Why the inconsistency between ARGF.readpartial and the rest of the ARGF methods? 2) Should the default external encoding take precedence over 'binmode'? ---------------------------------------- http://redmine.ruby-lang.org