Strange read behaviour on windows

C

Charles Lowe

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
from :0
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).
 
E

Eero Saynatkari

--TSQPSNmi3T91JED+
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

This is my first post to the ruby mailing lists, so let me first thank=20
all the people who's wonderful work I've made use of -- great stuff!.
=20
I've been trying to upload some large files, using=20
Net::HTTP::put#body_stream=3D, but have ran into some problems.
=20
Most of my initial testing was in cygwin, where most things "just work".= =20
upon trying it in the mingw32 build, i got https errors due to openssl=20
doing some non-block fcntls (IO#fcntl "not implemented on this=20
platform").
=20
I switched to the i386-mswin32, but now I getting some more fundamental= =20
problems, when doing file reads. I'm typically getting reads back under= =20
the requested size, (not a problem), but this is generating premature=20
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?

--TSQPSNmi3T91JED+
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (FreeBSD)

iD8DBQFFMy0t7Nh7RM4TrhIRAmWUAJ9BSIFBuSUv39dXYdLkMldO/Oq9LwCgrLE2
iRThd+D1DCIiPvjaIj1NpK4=
=ttqH
-----END PGP SIGNATURE-----

--TSQPSNmi3T91JED+--
 
C

Charles Lowe

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

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top