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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A2f332d9aa75eebdf670e7cc2e94257a?d=identicon&s=25 Aaron Chandler (vitalaaron)
on 2009-03-17 04:00
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
57a778becb5ea951889fa9f0b4e3bd15?d=identicon&s=25 Michael Linfield (macgoober)
on 2009-03-17 04:12
> 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
666b4e17b4bb0e2d999037a25f65a7cb?d=identicon&s=25 Heesob Park (phasis)
on 2009-03-17 04:31
(Received via mailing list)
Hi,

2009/3/17 Aaron Chandler <vitalaaron@gmail.com>:
> 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/brow...

Regards,

Park Heesob
A2f332d9aa75eebdf670e7cc2e94257a?d=identicon&s=25 Aaron Chandler (vitalaaron)
on 2009-03-17 04:52
> Try
> File.open('bigfile.flv','rb').read.length
>
> Refer to
> 
http://groups.google.com/group/comp.lang.ruby/brow...
>

This did the trick. Thanks tons.

-Aaron
This topic is locked and can not be replied to.