Reading bytes from a file

  • Thread starter Aaron Patterson
  • Start date
A

Aaron Patterson

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
 
W

William James

Aaron said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top