[Win32utils-devel] IO.read questions

Daniel Berger djberg96 at gmail.com
Thu May 3 04:34:51 UTC 2012

On Wed, May 2, 2012 at 7:02 PM, Luis Lavena <luislavena at gmail.com> wrote:
> On Wed, May 2, 2012 at 9:48 PM, Daniel Berger <djberg96 at gmail.com> wrote:
>> Hi,
>> ruby 1.9.3p125 (both mingw and mswin)
>> Is this a bug? I've got a file, test.txt, that contains nothing but this:
>> This is line 1
>> This is line 2
>> This is line 3
>> I ran these snippets of code:
>> IO.read('test.txt')          # => "This is line 1\nThis is line
>> 2\nThis is line 3\n"
>> IO.read('test.txt', nil)     # => "This is line 1\nThis is line
>> 2\nThis is line 3\n"
>> IO.read('test.txt', nil, 0) # => "This is line 1\r\nThis is line
>> 2\r\nThis is line 3\r\n"
>> Why are the native line endings retained if I specify an offset? Ruby
>> 1.8.x doesn't do that, btw.
> A regression fixed in patch level 194
> Root issue is caused by newline universal:
> https://bugs.ruby-lang.org/issues/6271
> Along other like File#pos

Thanks, I upgraded and it's working now.

I noticed another problem I think, though. According to the docs I
should be able to pass open_args and those should be passed along to
open(). However, this doesn't work:

IO.read('test.txt', open_args: ['rS']) # Try to force a sequential scan

But that blows up with an invalid access mode error, even though 'S'
is a legal mode on Windows. It looks to me like io.c is explicitly
checking mode values instead of just letting them pass through to the
open function and letting it fail on its own if they're invalid.

Or am I doing it wrong?



More information about the win32utils-devel mailing list