File.size() returning negative for large files?

Hi,

I'm getting a negative number being returned for large files when using
File.size()??? Any ideas? One of my ruby books says an Integer can be any
size??

I'm using:
- File.size(path)
- getting negative number responses for large files (e.g. -1001581 where
file was really around 3.2GB)
- using Windows XP
- using ruby 1.8.5 (2006-08-25) [i386-mswin32]

thanks

Hi,

At Sun, 3 Dec 2006 15:56:49 +0900,
Greg Hauptmann wrote in [ruby-talk:227857]:

I'm getting a negative number being returned for large files when using
File.size()??? Any ideas? One of my ruby books says an Integer can be any
size??

I'm using:
- File.size(path)
- getting negative number responses for large files (e.g. -1001581 where
file was really around 3.2GB)
- using Windows XP
- using ruby 1.8.5 (2006-08-25) [i386-mswin32]

1.8 series on MS-Windows doesn't contain large file support.

···

--
Nobu Nakada

Greg Hauptmann wrote:

Hi,

I'm getting a negative number being returned for large files when using
File.size()??? Any ideas? One of my ruby books says an Integer can be
any
size??

I'm using:
- File.size(path)
- getting negative number responses for large files (e.g. -1001581 where
file was really around 3.2GB)
- using Windows XP
- using ruby 1.8.5 (2006-08-25) [i386-mswin32]

thanks

It is not yours, but Windows fault.

by

TheR

···

--
Posted via http://www.ruby-forum.com/\.

Greg Hauptmann wrote:

Hi,

I'm getting a negative number being returned for large files when using
File.size()??? Any ideas? One of my ruby books says an Integer can be any
size??

I'm using:
- File.size(path)
- getting negative number responses for large files (e.g. -1001581 where
file was really around 3.2GB)
- using Windows XP
- using ruby 1.8.5 (2006-08-25) [i386-mswin32]

thanks

It's a bug in Ruby, not Windows. You can use win32-file, which redefines File.size so that it works properly on Windows.

It uses win32-file-stat behind the scenes, so make sure you've got the latest releases of both win32-file (0.5.2) and win32-file-stat (1.2.3).

Regards,

Dan

Is there a work around for this guys?

···

On 12/3/06, Damjan Rems <d_rems@yahoo.com> wrote:

Greg Hauptmann wrote:
> Hi,
>
> I'm getting a negative number being returned for large files when using
> File.size()??? Any ideas? One of my ruby books says an Integer can be
> any
> size??
>
> I'm using:
> - File.size(path)
> - getting negative number responses for large files (e.g. -1001581 where
> file was really around 3.2GB)
> - using Windows XP
> - using ruby 1.8.5 (2006-08-25) [i386-mswin32]
>
> thanks

It is not yours, but Windows fault.

by

TheR

--
Posted via http://www.ruby-forum.com/\.

[-1001581].pack('l').unpack('L').first # => 4293965715

···

On Dec 3, 2006, at 24:30 , Greg Hauptmann wrote:

On 12/3/06, Damjan Rems <d_rems@yahoo.com> wrote:

Greg Hauptmann wrote:

I'm getting a negative number being returned for large files when using File.size()??? Any ideas? One of my ruby books says an Integer can be any size??

I'm using:
- File.size(path)
- getting negative number responses for large files (e.g. -1001581 where file was really around 3.2GB)

It is not yours, but Windows fault.

Is there a work around for this guys?

--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net

A: Yes
Q: Is top-posting bad?
  — Derek Milhous Zumsteg

excellent!! thanks Eric - who knows how long that would have taken me to
discover for myself :slight_smile:

···

On 12/3/06, Eric Hodel <drbrain@segment7.net> wrote:

On Dec 3, 2006, at 24:30 , Greg Hauptmann wrote:
> On 12/3/06, Damjan Rems <d_rems@yahoo.com> wrote:
>> Greg Hauptmann wrote:
>>> I'm getting a negative number being returned for large files when
>>> using File.size()??? Any ideas? One of my ruby books says an
>>> Integer can be any size??
>>>
>>> I'm using:
>>> - File.size(path)
>>> - getting negative number responses for large files (e.g.
>>> -1001581 where file was really around 3.2GB)
>>
>> It is not yours, but Windows fault.
>
> Is there a work around for this guys?

[-1001581].pack('l').unpack('L').first # => 4293965715

--
Eric Hodel - drbrain@segment7.net - http://blog.segment7.net

A: Yes
Q: Is top-posting bad?
  — Derek Milhous Zumsteg

However, notice that for VERY large files, (larger than 4Gb, I guess,
or 4294967296 bytes), that method fails also

[4294967296].pack('l')

is the same as

[4294967296*2].pack('l')

So something different ought to be used. You might as well get
the info from "system (dir)" or similar for your specific case.

Pedro

···

On 12/3/06, Eric Hodel <drbrain@segment7.net> wrote:

On Dec 3, 2006, at 24:30 , Greg Hauptmann wrote:
> On 12/3/06, Damjan Rems <d_rems@yahoo.com> wrote:
>> Greg Hauptmann wrote:
>>> I'm getting a negative number being returned for large files when
>>> using File.size()??? Any ideas? One of my ruby books says an
>>> Integer can be any size??
>>>
>>> I'm using:
>>> - File.size(path)
>>> - getting negative number responses for large files (e.g.
>>> -1001581 where file was really around 3.2GB)
>>
>> It is not yours, but Windows fault.
>
> Is there a work around for this guys?

[-1001581].pack('l').unpack('L').first # => 4293965715

--
Pedro Fortuny Ayuso
C/Capuchinos 14, 1. 47006 Valladolid. SPAIN

Are all your files under 4GB?

···

On Sun, Dec 03, 2006 at 07:58:19PM +0900, Greg Hauptmann wrote:

On 12/3/06, Eric Hodel <drbrain@segment7.net> wrote:
>On Dec 3, 2006, at 24:30 , Greg Hauptmann wrote:
>> On 12/3/06, Damjan Rems <d_rems@yahoo.com> wrote:
>>> It is not yours, but Windows fault.
>>
>> Is there a work around for this guys?
>
>[-1001581].pack('l').unpack('L').first # => 4293965715
>
excellent!! thanks Eric - who knows how long that would have taken me to
discover for myself :slight_smile:

--
Mauricio Fernandez - http://eigenclass.org - singular Ruby

Pedro Fortuny Ayuso wrote:

···

On 12/3/06, Eric Hodel <drbrain@segment7.net> wrote:

On Dec 3, 2006, at 24:30 , Greg Hauptmann wrote:
> On 12/3/06, Damjan Rems <d_rems@yahoo.com> wrote:
>> Greg Hauptmann wrote:
>>> I'm getting a negative number being returned for large files when
>>> using File.size()??? Any ideas? One of my ruby books says an
>>> Integer can be any size??
>>>
>>> I'm using:
>>> - File.size(path)
>>> - getting negative number responses for large files (e.g.
>>> -1001581 where file was really around 3.2GB)
>>
>> It is not yours, but Windows fault.
>
> Is there a work around for this guys?

[-1001581].pack('l').unpack('L').first # => 4293965715

However, notice that for VERY large files, (larger than 4Gb, I guess,
or 4294967296 bytes), that method fails also

[4294967296].pack('l')

is the same as

[4294967296*2].pack('l')

So something different ought to be used. You might as well get
the info from "system (dir)" or similar for your specific case.

Pedro

Try 'Q' instead. Or, just use win32-file. :slight_smile:

Regards,

Dan

where do you get win32-file? I don't see it in the api or on the wiki? Is
it a gem I have to load?

Tks

···

On 12/4/06, Daniel Berger <djberg96@gmail.com> wrote:

Pedro Fortuny Ayuso wrote:
> On 12/3/06, Eric Hodel <drbrain@segment7.net> wrote:
>>
>> On Dec 3, 2006, at 24:30 , Greg Hauptmann wrote:
>> > On 12/3/06, Damjan Rems <d_rems@yahoo.com> wrote:
>> >> Greg Hauptmann wrote:
>> >>> I'm getting a negative number being returned for large files when
>> >>> using File.size()??? Any ideas? One of my ruby books says an
>> >>> Integer can be any size??
>> >>>
>> >>> I'm using:
>> >>> - File.size(path)
>> >>> - getting negative number responses for large files (e.g.
>> >>> -1001581 where file was really around 3.2GB)
>> >>
>> >> It is not yours, but Windows fault.
>> >
>> > Is there a work around for this guys?
>>
>> [-1001581].pack('l').unpack('L').first # => 4293965715
>
> However, notice that for VERY large files, (larger than 4Gb, I guess,
> or 4294967296 bytes), that method fails also
>
> [4294967296].pack('l')
>
> is the same as
>
> [4294967296*2].pack('l')
>
> So something different ought to be used. You might as well get
> the info from "system (dir)" or similar for your specific case.
>
> Pedro
>

Try 'Q' instead. Or, just use win32-file. :slight_smile:

Regards,

Dan

Greg Hauptmann wrote:

where do you get win32-file? I don't see it in the api or on the wiki? Is
it a gem I have to load?

http://rubyforge.org/projects/win32utils/

Greg Hauptmann wrote:

where do you get win32-file? I don't see it in the api or on the wiki? Is
it a gem I have to load?

The gem comes per default with the one click installer. Or, at least, I
see it there and can't remember installing it :stuck_out_tongue_winking_eye:

David Vallner