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

**URL:** <https://www.ruby-forum.com/t/file-open-read-length-result-incorrect-on-windows-server/163065>\
**Category:** Ruby\
**Created:** [March 17, 2009, 4:00am UTC](https://www.ruby-forum.com/t/file-open-read-length-result-incorrect-on-windows-server/163065 "2009-03-17T04:00:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [March 17, 2009, 4:00am UTC](https://www.ruby-forum.com/t/file-open-read-length-result-incorrect-on-windows-server/163065/1 "2009-03-17T04:00:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [March 17, 2009, 4:12am UTC](https://www.ruby-forum.com/t/file-open-read-length-result-incorrect-on-windows-server/163065/2 "2009-03-17T04:12:38Z")

</div>

> 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

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [March 17, 2009, 4:31am UTC](https://www.ruby-forum.com/t/file-open-read-length-result-incorrect-on-windows-server/163065/3 "2009-03-17T04:31:42Z")

</div>

Hi,

2009/3/17 Aaron C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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](http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/47209184b760c8e4/e8aca721faa8ac67)

Regards,

Park H.

---

<div class="post-metadata">

**Author:** ![acampos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/919ad9/32.png) [@acampos](https://www.ruby-forum.com/u/acampos)\
**Post date:** [March 17, 2009, 4:52am UTC](https://www.ruby-forum.com/t/file-open-read-length-result-incorrect-on-windows-server/163065/4 "2009-03-17T04:52:18Z")

</div>

> Try  
> File.open(‘bigfile.flv’,‘rb’).read.length
> 
> Refer to  
> [http://groups.google.com/group/comp.lang.ruby/browse\_thread/thread/47209184b760c8e4/e8aca721faa8ac67](http://groups.google.com/group/comp.lang.ruby/browse_thread/thread/47209184b760c8e4/e8aca721faa8ac67)

This did the trick. Thanks tons.

-Aaron
