Forum: Ruby Reading bytes from a file

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.
A24e072d6092870feff0d5016ff2cdd0?d=identicon&s=25 Aaron Patterson (Guest)
on 2007-01-03 20:30
(Received via mailing list)
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
A24e072d6092870feff0d5016ff2cdd0?d=identicon&s=25 Aaron Patterson (Guest)
on 2007-01-03 20:34
(Received via mailing list)
Oops.....  Just needed to require 'readbytes'

--Aaron
2ee1a7960cc761a6e92efb5000c0f2c9?d=identicon&s=25 William James (Guest)
on 2007-01-03 21:46
(Received via mailing list)
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
This topic is locked and can not be replied to.