This is a loose adaption of readbytes.rb, but with more flexibility and StringIO support.
Public instance methods
e_read
(n, mesg = nil)
Reads exactly n bytes.
If the data read is nil an EOFError is raised.
If the data read is too short a MissingDataError is raised and the read data is obtainable via its data method.
[show source]
# File lib/nwn/io.rb, line 24 def e_read(n, mesg = nil) str = read(n) if str == nil raise EOFError, "End of file reached" end if str.size < n raise MissingDataError.new("data truncated" + (mesg ? ": " + mesg : nil), str) end str end