[Win32utils-devel] IO.read questions

Daniel Berger djberg96 at gmail.com
Thu May 3 05:25:18 UTC 2012


On Wed, May 2, 2012 at 11:01 PM, Heesob Park <phasis at gmail.com> wrote:
> Hi,
>
> 2012/5/3 Daniel Berger <djberg96 at gmail.com>
>>
>> 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?
>>
>
> I think that is a nice feature.
>
> Why don't you make a feature request on http://bugs.ruby-lang.org/ ?

Maybe I will.

> Even if it is rejected, you can make your own IO with the WinRuby :)

Oh, I plan on it. In fact I was playing with the ffi branch of the
win32-nio library again today. The NIO.read benchmarks are pretty
good. Much faster than the default IO.read method.

I couldn't get NIO.readlines to work, though. I'm doing something
wrong with the FileSegment pointer in FFI, but I'm not sure what.
Though, if memory serves, the ReadFileScatter approach was actually
slower than the default implementation. But, if you're up for taking a
look, I would appreciate it.

Regards,

Dan


More information about the win32utils-devel mailing list