File.open().read.length result incorrect on Windows Server

Discussion in 'Ruby' started by Aaron Chandler, Mar 17, 2009.

  1. Hi,

    I need to open and read a 7.6M file on an EC2 Windows Server 2003
    machine, and when I try using:

    File.open('bigfile.flv').read.length

    the result I get is 22731 (wrong) with the last characters of the file
    data being "\334r\227\000\220-".

    In comparison, when I run this same command for the same file on my Mac,
    I get 7941109 (correct) with the last characters of the file data being
    "\000\000\000\250"

    It appears as if the file data is being truncated in Windows. Anyone
    have an idea as to why I would be seeing results like this?

    Thanks,
    Aaron
    --
    Posted via http://www.ruby-forum.com/.
     
    Aaron Chandler, Mar 17, 2009
    #1
    1. Advertising

  2. > It appears as if the file data is being truncated in Windows. Anyone
    > have an idea as to why I would be seeing results like this?


    Not a good explanation of WHY per'se but I've previously encountered
    similar problems when opening large files on windows. What wouldn't open
    in windows would open in Linux just fine.

    Maybe try a different read method such as:

    IO.read("filename.flv").length

    or

    File.stat("filename.flv").size



    I don't have a large dataset I can duplicate the problem on at the
    moment so I can't test this for you :(

    Regards,

    - Mac


    --
    Posted via http://www.ruby-forum.com/.
     
    Michael Linfield, Mar 17, 2009
    #2
    1. Advertising

  3. Aaron Chandler

    Heesob Park Guest

    Hi,

    2009/3/17 Aaron Chandler <>:
    > Hi,
    >
    > I need to open and read a 7.6M file on an EC2 Windows Server 2003
    > machine, and when I try using:
    >
    > File.open('bigfile.flv').read.length
    >
    > the result I get is 22731 (wrong) with the last characters of the file
    > data being "\334r\227\000\220-".
    >
    > In comparison, when I run this same command for the same file on my Mac,
    > I get 7941109 (correct) with the last characters of the file data being
    > "\000\000\000\250"
    >
    > It appears as if the file data is being truncated in Windows. Anyone
    > have an idea as to why I would be seeing results like this?
    >

    Try
    File.open('bigfile.flv','rb').read.length

    Refer to http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/47209184b760c8e4/e8aca721faa8ac67

    Regards,

    Park Heesob
     
    Heesob Park, Mar 17, 2009
    #3
  4. Aaron Chandler, Mar 17, 2009
    #4
    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. Sullivan WxPyQtKinter
    Replies:
    1
    Views:
    423
    Tim Roberts
    Apr 7, 2006
  2. NM
    Replies:
    13
    Views:
    567
    glen herrmannsfeldt
    Sep 17, 2005
  3. Replies:
    1
    Views:
    326
    bruce barker
    May 31, 2007
  4. Michael Tan
    Replies:
    32
    Views:
    1,082
    Ara.T.Howard
    Jul 21, 2005
  5. Chris Dwan
    Replies:
    4
    Views:
    170
    Nobuyoshi Nakada
    Jul 23, 2007
Loading...

Share This Page