Strange read behaviour on windows

This is my first post to the ruby mailing lists, so let me first thank
all the people who's wonderful work I've made use of -- great stuff!.

I've been trying to upload some large files, using
Net::HTTP::Put#body_stream=, but have ran into some problems.

Most of my initial testing was in cygwin, where most things "just work".
upon trying it in the mingw32 build, i got https errors due to openssl
doing some non-block fcntls (IO#fcntl "not implemented on this
platform").

I switched to the i386-mswin32, but now I getting some more fundamental
problems, when doing file reads. I'm typically getting reads back under
the requested size, (not a problem), but this is generating premature
EOF errors. If I just use File#read, I correctly get the entire file.

An irb snippet says it best:

irb(main):139:0> f.pos
=> 1605632
irb(main):140:0> f.read 1024
=> nil
irb(main):141:0> f.pos
=> 1605632
irb(main):142:0> f.read 1024
=> nil
irb(main):143:0> f.sysread 1024
=>
"R\326ER6qJ\302So\233\321\373\25218\205\260u*\245\212`k\246\300Vo\233\311\373
\252)8\222}z\367\270g58\026x\022q"
irb(main):144:0> f.pos
=> 1606656
irb(main):145:0> f.sysread 1024
=>
"\340G\370\023\3023\b:R\264C\225\326\213\276\335\244\234O)N\035$3N\307\017\36
0d\261\321A\245\334\250y|\025lo\253\306*\205\316\246\276$`\366\022\255"
irb(main):146:0> _.length
=> 52
irb(main):147:0> f.sysread 1024
EOFError: end of file reached
        from (irb):147:in `sysread'
        from (irb):147
irb(main):148:0> f.pos
=> 1607680
irb(main):149:0> RUBY_PLATFORM
=> "i386-mswin32"

(FWIW, the file f in question, is just the one-click installer -
ruby185-21.exe. f.stat.size correctly yields 27644627).

···

from :0

--
Posted via http://www.ruby-forum.com/.

Just on an off-chance, is your file open in binary mode?

···

On 2006.10.16 15:41, Charles Lowe wrote:

This is my first post to the ruby mailing lists, so let me first thank
all the people who's wonderful work I've made use of -- great stuff!.

I've been trying to upload some large files, using
Net::HTTP::Put#body_stream=, but have ran into some problems.

Most of my initial testing was in cygwin, where most things "just work".
upon trying it in the mingw32 build, i got https errors due to openssl
doing some non-block fcntls (IO#fcntl "not implemented on this
platform").

I switched to the i386-mswin32, but now I getting some more fundamental
problems, when doing file reads. I'm typically getting reads back under
the requested size, (not a problem), but this is generating premature
EOF errors. If I just use File#read, I correctly get the entire file.

Eero Saynatkari wrote:

···

On 2006.10.16 15:41, Charles Lowe wrote:

I switched to the i386-mswin32, but now I getting some more fundamental
problems, when doing file reads. I'm typically getting reads back under
the requested size, (not a problem), but this is generating premature
EOF errors. If I just use File#read, I correctly get the entire file.

Just on an off-chance, is your file open in binary mode?

Oops. Now I feel like an idiot; 'rb' should be the default! :slight_smile: stupid
windows...

Thank you though, had been banging my head against that one for a while.

--
Posted via http://www.ruby-forum.com/\.