Strange read behaviour on windows

Discussion in 'Ruby' started by Charles Lowe, Oct 16, 2006.

  1. Charles Lowe

    Charles Lowe Guest

    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).

    --
    Posted via http://www.ruby-forum.com/.
    Charles Lowe, Oct 16, 2006
    #1
    1. Advertising

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

    On 2006.10.16 15:41, Charles Lowe wrote:
    > 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+--
    Eero Saynatkari, Oct 16, 2006
    #2
    1. Advertising

  3. Charles Lowe

    Charles Lowe Guest

    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! :) stupid
    windows...

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

    --
    Posted via http://www.ruby-forum.com/.
    Charles Lowe, Oct 16, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Norbert
    Replies:
    2
    Views:
    331
    Norbert
    Dec 1, 2006
  2. Qu0ll
    Replies:
    28
    Views:
    730
    Qu0ll
    Nov 15, 2007
  3. Replies:
    13
    Views:
    1,053
  4. James Unterburger

    std.textio.read strange behaviour?!

    James Unterburger, Jun 26, 2008, in forum: VHDL
    Replies:
    3
    Views:
    521
    James Unterburger
    Jun 26, 2008
  5. mastermagrath
    Replies:
    4
    Views:
    395
    robic0
    Dec 1, 2005
Loading...

Share This Page