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 24: def e_read(n, mesg = nil) 25: str = read(n) 26: if str == nil 27: raise EOFError, "End of file reached" 28: end 29: if str.size < n 30: raise MissingDataError.new("data truncated" + (mesg ? ": " + mesg : nil), str) 31: end 32: str 33: end