File#size

I am thinking this would be a nice function to have in the stdlib.

File#size

thoughts?
-=r

On 07.02.2009 15:26, Roger P. wrote:

I am thinking this would be a nice function to have in the stdlib.

File#size

thoughts?

Others seems to agree

http://www.ruby-doc.org/core/classes/File.html#M002590

robert

Hi –

On Sat, 7 Feb 2009, Robert K. wrote:

On 07.02.2009 15:26, Roger P. wrote:

I am thinking this would be a nice function to have in the stdlib.

File#size

thoughts?

Others seems to agree

class File - RDoc Documentation

I think Roger means an instance method.

David


David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (The Well-Grounded Rubyist)

http://www.wishsight.com => Independent, social wishlist management!

How about file.stat.size ?

Dylan E. wrote:

How about file.stat.size ?

ooh that’s really close.
I might want one that takes into account unflushed buffers, though.
Apparently .stat.size doesn’t quite.

a.write ‘abc’
=> 3

a.stat.size
=> 0

a.flush
=> #<File:README>

a.stat.size
=> 3

But at least it’s pretty close.
-=r

I didn’t know that, but it’s something to bear in mind. I haven’t read
the
code but i suspect that it is a shortcut for File::Stat.new(‘file’).size

On 07.02.2009 16:34, Roger P. wrote:

=> 0

a.flush
=> #<File:README>
a.stat.size
=> 3

But at least it’s pretty close.
-=r

So you want to know how much you have written? Then use #tell
http://www.ruby-doc.org/core/classes/IO.html#M002304

robert

So you want to know how much you have written? Then use #tell
class IO - RDoc Documentation

robert

It appears that #tell gives you the size of the file you’re writing to,
and File#stat.size tells you the filesize of files you’re reading from,
is that right?

Roger P. wrote:

So you want to know how much you have written? Then use #tell
class IO - RDoc Documentation

robert

It appears that #tell gives you the size of the file you’re writing to,
and File#stat.size tells you the filesize of files you’re reading from,
is that right?

#tell tells you where you’re at in the file, not the size of the file.
If you’re in the middle of reading a file, #tell tells you how far you
are from the start of file. If you seek to offset 100 in a 100,000 byte
file, #tell returns 100, not 100,000.

$ ri IO#tell
---------------------------------------------------------------- IO#tell
ios.pos => integer
ios.tell => integer

  Returns the current offset (in bytes) of ios.

     f = File.new("testfile")
     f.pos    #=> 0
     f.gets   #=> "This is line one\n"
     f.pos    #=> 17

thoughts?

Others seems to agree

class File - RDoc Documentation

I think Roger means an instance method.

There are many other File class methods for which it would be convenient
to have instance method counterparts. This and much more can be found in
the standard library Pathname:

http://www.ruby-doc.org/stdlib/libdoc/pathname/rdoc/classes/Pathname.html


Lars H.

“If anyone disagrees with anything I say, I am quite prepared not only
to
retract it, but also to deny under oath that I ever said it.” -Tom
Lehrer