[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Reading bytes from a file

Aaron Patterson

1/3/2007 7:29:00 PM

I'm trying to read bytes from a file, and it would be handy if there was
a method that threw an exception if I couldn't read that many bytes, or
encountered an EOF.

IO#readbytes seems like the perfect method, but I have an instance of File.
The documentation says that File inherits from IO, but the File instance
doesn't seem to have the readbytes method. Am I missing something?

--Aaron

--
Aaron Patterson
http://tenderlovem...

2 Answers

Aaron Patterson

1/3/2007 7:33:00 PM

0

Oops..... Just needed to require 'readbytes'

--Aaron

On Thu, Jan 04, 2007 at 04:28:52AM +0900, Aaron Patterson wrote:
> I'm trying to read bytes from a file, and it would be handy if there was
> a method that threw an exception if I couldn't read that many bytes, or
> encountered an EOF.
>
> IO#readbytes seems like the perfect method, but I have an instance of File.
> The documentation says that File inherits from IO, but the File instance
> doesn't seem to have the readbytes method. Am I missing something?
>
> --Aaron
>
> --
> Aaron Patterson
> http://tenderlovem...
>

--
Aaron Patterson
http://tenderlovem...

William James

1/3/2007 8:42:00 PM

0


Aaron Patterson wrote:
> I'm trying to read bytes from a file, and it would be handy if there was
> a method that threw an exception if I couldn't read that many bytes, or
> encountered an EOF.
>
> IO#readbytes seems like the perfect method, but I have an instance of File.
> The documentation says that File inherits from IO, but the File instance
> doesn't seem to have the readbytes method. Am I missing something?

s = open('junk'){|f| f.read(10) }
fail if s.size < 10